Project

General

Profile

« Previous | Next » 

Revision 12594

schemas/util.sql: mk_keys_func(): create the keys() function directly from the keys record type, to support creating just a custom keys record type rather than also a custom keys() function (which is fairly complicated to do, thanks to the need to define a separate custom return type)

View differences:

trunk/schemas/util.sql
2101 2101
SELECT util.create_if_not_exists($$
2102 2102
CREATE TYPE $$||util.prefixed_name($3||'_', $1)||$$ AS
2103 2103
($$||util.mk_typed_cols_list($2)||$$);
2104
$$);
2104 2105

  
2106
SELECT util.mk_keys_func($1, util.prefixed_name($3||'_', $1)::regtype, $3);
2107
$_$;
2108

  
2109

  
2110
--
2111
-- Name: mk_keys_func(regtype, regtype, text); Type: FUNCTION; Schema: util; Owner: -
2112
--
2113

  
2114
CREATE FUNCTION mk_keys_func(type regtype, return_type regtype, name text DEFAULT 'keys'::text) RETURNS void
2115
    LANGUAGE sql
2116
    AS $_$
2117
SELECT util.create_if_not_exists($$
2105 2118
CREATE FUNCTION $$||util.qual_name(util.schema($1), $3)||$$(value $$
2106 2119
||util.qual_name($1)||$$)
2107
  RETURNS $$||util.prefixed_name($3||'_', $1)||$$ AS
2120
  RETURNS $$||util.qual_name($2)||$$ AS
2108 2121
$BODY1$
2109 2122
SELECT ROW($$||
2110
(SELECT COALESCE(string_agg($$$1.$$||quote_ident((unnest).col_name), ', '), '')
2111
FROM unnest($2)) ||$$)::$$||util.prefixed_name($3||'_', $1)||$$
2123
(SELECT COALESCE(string_agg($$$1.$$||quote_ident((col).col_name), ', '), '')
2124
FROM util.typed_cols($2) col) ||$$)::$$||util.qual_name($2)||$$
2112 2125
$BODY1$
2113 2126
  LANGUAGE sql IMMUTABLE
2114 2127
  COST 100;
2115
$$)
2128
$$);
2116 2129
$_$;
2117 2130

  
2118 2131

  

Also available in: Unified diff