Revision 12446
Added by Aaron Marcuse-Kubitza almost 11 years ago
trunk/schemas/util.sql | ||
---|---|---|
555 | 555 |
-- |
556 | 556 |
|
557 | 557 |
CREATE FUNCTION added_cols(table_ regclass, names regclass) RETURNS SETOF text |
558 |
LANGUAGE sql STABLE STRICT
|
|
558 |
LANGUAGE sql STABLE |
|
559 | 559 |
AS $_$ |
560 | 560 |
SELECT util.derived_cols($1, $2) |
561 | 561 |
UNION |
... | ... | |
621 | 621 |
-- |
622 | 622 |
|
623 | 623 |
CREATE FUNCTION append_comment(table_ regclass, comment text) RETURNS void |
624 |
LANGUAGE sql STRICT
|
|
624 |
LANGUAGE sql |
|
625 | 625 |
AS $_$ |
626 | 626 |
SELECT util.set_comment($1, concat(util.comment($1), $2)) |
627 | 627 |
$_$; |
... | ... | |
683 | 683 |
-- |
684 | 684 |
|
685 | 685 |
CREATE FUNCTION cluster_index(table_ regclass) RETURNS regclass |
686 |
LANGUAGE sql STABLE STRICT
|
|
686 |
LANGUAGE sql STABLE |
|
687 | 687 |
AS $_$ |
688 | 688 |
SELECT indexrelid FROM pg_index WHERE indrelid = $1 AND indisclustered |
689 | 689 |
$_$; |
... | ... | |
835 | 835 |
-- |
836 | 836 |
|
837 | 837 |
CREATE FUNCTION col_names(table_ regclass) RETURNS SETOF text |
838 |
LANGUAGE sql STABLE STRICT
|
|
838 |
LANGUAGE sql STABLE |
|
839 | 839 |
AS $_$ |
840 | 840 |
SELECT attname::text |
841 | 841 |
FROM pg_attribute |
... | ... | |
885 | 885 |
-- |
886 | 886 |
|
887 | 887 |
CREATE FUNCTION comment(element oid) RETURNS text |
888 |
LANGUAGE sql STABLE STRICT
|
|
888 |
LANGUAGE sql STABLE |
|
889 | 889 |
AS $_$ |
890 | 890 |
SELECT description FROM pg_description WHERE objoid = $1 |
891 | 891 |
$_$; |
... | ... | |
998 | 998 |
-- |
999 | 999 |
|
1000 | 1000 |
CREATE FUNCTION derived_cols(table_ regclass, names regclass) RETURNS SETOF text |
1001 |
LANGUAGE sql STABLE STRICT
|
|
1001 |
LANGUAGE sql STABLE |
|
1002 | 1002 |
AS $_$ |
1003 | 1003 |
SELECT util.eval2set($$ |
1004 | 1004 |
SELECT col |
... | ... | |
1099 | 1099 |
-- |
1100 | 1100 |
|
1101 | 1101 |
CREATE FUNCTION do_optionally_ignore(sql text, ignore boolean) RETURNS void |
1102 |
LANGUAGE sql STRICT
|
|
1102 |
LANGUAGE sql |
|
1103 | 1103 |
AS $_$ |
1104 | 1104 |
SELECT CASE WHEN $2 THEN util.try_create($1) ELSE util.create_if_not_exists($1) END |
1105 | 1105 |
$_$; |
... | ... | |
1119 | 1119 |
-- |
1120 | 1120 |
|
1121 | 1121 |
CREATE FUNCTION drop_column(col col_ref, force boolean DEFAULT false) RETURNS void |
1122 |
LANGUAGE sql STRICT
|
|
1122 |
LANGUAGE sql |
|
1123 | 1123 |
AS $_$ |
1124 | 1124 |
SELECT util.eval($$ALTER TABLE $$||$1.table_||$$ DROP COLUMN IF EXISTS $$|| |
1125 | 1125 |
quote_ident($1.name)||util._if($2, $$ CASCADE$$, ''::text)) |
... | ... | |
1200 | 1200 |
-- |
1201 | 1201 |
|
1202 | 1202 |
CREATE FUNCTION drop_table(table_ text, force boolean DEFAULT false) RETURNS void |
1203 |
LANGUAGE sql STRICT
|
|
1203 |
LANGUAGE sql |
|
1204 | 1204 |
AS $_$ |
1205 | 1205 |
SELECT util.drop_relation('TABLE', $1, $2) |
1206 | 1206 |
$_$; |
... | ... | |
1220 | 1220 |
-- |
1221 | 1221 |
|
1222 | 1222 |
CREATE FUNCTION drop_view(view_ text, force boolean DEFAULT false) RETURNS void |
1223 |
LANGUAGE sql STRICT
|
|
1223 |
LANGUAGE sql |
|
1224 | 1224 |
AS $_$ |
1225 | 1225 |
SELECT util.drop_relation('VIEW', $1, $2) |
1226 | 1226 |
$_$; |
... | ... | |
1423 | 1423 |
-- |
1424 | 1424 |
|
1425 | 1425 |
CREATE FUNCTION existing_cols(table_ regclass, VARIADIC col_names text[]) RETURNS SETOF text |
1426 |
LANGUAGE sql STABLE STRICT
|
|
1426 |
LANGUAGE sql STABLE |
|
1427 | 1427 |
AS $_$ |
1428 | 1428 |
SELECT col_name |
1429 | 1429 |
FROM unnest($2) s (col_name) |
... | ... | |
1687 | 1687 |
-- |
1688 | 1688 |
|
1689 | 1689 |
CREATE FUNCTION is_constant(col col_ref) RETURNS boolean |
1690 |
LANGUAGE sql STABLE STRICT
|
|
1690 |
LANGUAGE sql STABLE |
|
1691 | 1691 |
AS $_$ |
1692 | 1692 |
SELECT COALESCE(util.col_comment($1) LIKE 'constant%', false) |
1693 | 1693 |
$_$; |
... | ... | |
1922 | 1922 |
-- |
1923 | 1923 |
|
1924 | 1924 |
CREATE FUNCTION mk_const_col(col col_ref, value anyelement) RETURNS void |
1925 |
LANGUAGE sql STRICT
|
|
1925 |
LANGUAGE sql |
|
1926 | 1926 |
AS $_$ |
1927 | 1927 |
SELECT util.create_if_not_exists($$ |
1928 | 1928 |
ALTER TABLE $$||$1.table_||$$ ADD COLUMN $$ |
... | ... | |
1978 | 1978 |
-- |
1979 | 1979 |
|
1980 | 1980 |
CREATE FUNCTION mk_map_table(table_ text) RETURNS void |
1981 |
LANGUAGE sql STRICT
|
|
1981 |
LANGUAGE sql |
|
1982 | 1982 |
AS $_$ |
1983 | 1983 |
SELECT util.create_if_not_exists($$ |
1984 | 1984 |
CREATE TABLE $$||$1||$$ |
... | ... | |
2048 | 2048 |
-- |
2049 | 2049 |
|
2050 | 2050 |
CREATE FUNCTION mk_source_col(table_ regclass) RETURNS void |
2051 |
LANGUAGE sql STRICT
|
|
2051 |
LANGUAGE sql |
|
2052 | 2052 |
AS $_$ |
2053 | 2053 |
SELECT util.mk_const_col(($1, 'source'), util.schema($1)) |
2054 | 2054 |
$_$; |
... | ... | |
2204 | 2204 |
-- |
2205 | 2205 |
|
2206 | 2206 |
CREATE FUNCTION name(type regtype) RETURNS text |
2207 |
LANGUAGE sql STABLE STRICT
|
|
2207 |
LANGUAGE sql STABLE |
|
2208 | 2208 |
AS $_$ |
2209 | 2209 |
SELECT typname::text FROM pg_type WHERE oid = $1 |
2210 | 2210 |
$_$; |
... | ... | |
2301 | 2301 |
-- |
2302 | 2302 |
|
2303 | 2303 |
CREATE FUNCTION qual_name(table_ regclass) RETURNS text |
2304 |
LANGUAGE sql STABLE STRICT
|
|
2304 |
LANGUAGE sql STABLE |
|
2305 | 2305 |
SET search_path TO pg_temp |
2306 | 2306 |
AS $_$ |
2307 | 2307 |
SELECT $1::text |
... | ... | |
2313 | 2313 |
-- |
2314 | 2314 |
|
2315 | 2315 |
CREATE FUNCTION qual_name(type regtype) RETURNS text |
2316 |
LANGUAGE sql STABLE STRICT
|
|
2316 |
LANGUAGE sql STABLE |
|
2317 | 2317 |
SET search_path TO pg_temp |
2318 | 2318 |
AS $_$ |
2319 | 2319 |
SELECT $1::text |
... | ... | |
2334 | 2334 |
-- |
2335 | 2335 |
|
2336 | 2336 |
CREATE FUNCTION qual_name(type unknown) RETURNS text |
2337 |
LANGUAGE sql STABLE STRICT
|
|
2337 |
LANGUAGE sql STABLE |
|
2338 | 2338 |
AS $_$ |
2339 | 2339 |
SELECT util.qual_name($1::text::regtype) |
2340 | 2340 |
$_$; |
... | ... | |
2565 | 2565 |
-- |
2566 | 2566 |
|
2567 | 2567 |
CREATE FUNCTION rename_cols(table_ regclass, renames anyelement) RETURNS void |
2568 |
LANGUAGE sql STRICT
|
|
2568 |
LANGUAGE sql |
|
2569 | 2569 |
AS $_$ |
2570 | 2570 |
SELECT util.try_create($$ALTER TABLE $$||$1||$$ RENAME $$ |
2571 | 2571 |
||quote_ident(name)||$$ TO $$||quote_ident($2 -> name)) |
... | ... | |
2644 | 2644 |
-- |
2645 | 2645 |
|
2646 | 2646 |
CREATE FUNCTION reset_col_names(table_ regclass, names regclass) RETURNS void |
2647 |
LANGUAGE sql STRICT
|
|
2647 |
LANGUAGE sql |
|
2648 | 2648 |
AS $_$ |
2649 | 2649 |
SELECT util.eval($$DELETE FROM $$||$2||$$ WHERE "from" LIKE ':%'$$); |
2650 | 2650 |
SELECT util.mk_derived_col(($2, 'to'), $$"from"$$, overwrite := true); |
... | ... | |
2667 | 2667 |
-- |
2668 | 2668 |
|
2669 | 2669 |
CREATE FUNCTION reset_map_table(table_ text) RETURNS void |
2670 |
LANGUAGE sql STRICT
|
|
2670 |
LANGUAGE sql |
|
2671 | 2671 |
AS $_$ |
2672 | 2672 |
SELECT util.drop_table($1); |
2673 | 2673 |
SELECT util.mk_map_table($1); |
... | ... | |
2902 | 2902 |
-- |
2903 | 2903 |
|
2904 | 2904 |
CREATE FUNCTION search_path_append(schemas text) RETURNS void |
2905 |
LANGUAGE sql STRICT
|
|
2905 |
LANGUAGE sql |
|
2906 | 2906 |
AS $_$ |
2907 | 2907 |
SELECT util.eval( |
2908 | 2908 |
$$SET search_path TO $$||current_setting('search_path')||$$, $$||$1); |
... | ... | |
3026 | 3026 |
-- |
3027 | 3027 |
|
3028 | 3028 |
CREATE FUNCTION set_comment(table_ regclass, comment text) RETURNS void |
3029 |
LANGUAGE sql STRICT
|
|
3029 |
LANGUAGE sql |
|
3030 | 3030 |
AS $_$ |
3031 | 3031 |
SELECT util.eval($$COMMENT ON TABLE $$||$1||$$ IS $$||quote_nullable($2)) |
3032 | 3032 |
$_$; |
... | ... | |
3120 | 3120 |
-- |
3121 | 3121 |
|
3122 | 3122 |
CREATE FUNCTION table_flag__get(table_ regclass, flag text) RETURNS boolean |
3123 |
LANGUAGE sql STABLE STRICT
|
|
3123 |
LANGUAGE sql STABLE |
|
3124 | 3124 |
AS $_$ |
3125 | 3125 |
SELECT COUNT(*) > 0 FROM pg_constraint |
3126 | 3126 |
WHERE conrelid = $1 AND contype = 'c' AND conname = $2 |
... | ... | |
3141 | 3141 |
-- |
3142 | 3142 |
|
3143 | 3143 |
CREATE FUNCTION table_flag__set(table_ regclass, flag text) RETURNS void |
3144 |
LANGUAGE sql STRICT
|
|
3144 |
LANGUAGE sql |
|
3145 | 3145 |
AS $_$ |
3146 | 3146 |
SELECT util.create_if_not_exists($$ALTER TABLE $$||$1||$$ ADD CONSTRAINT $$ |
3147 | 3147 |
||quote_ident($2)||$$ CHECK (true)$$) |
... | ... | |
3163 | 3163 |
-- |
3164 | 3164 |
|
3165 | 3165 |
CREATE FUNCTION table_nulls_mapped__get(table_ regclass) RETURNS boolean |
3166 |
LANGUAGE sql STABLE STRICT
|
|
3166 |
LANGUAGE sql STABLE |
|
3167 | 3167 |
AS $_$ |
3168 | 3168 |
SELECT util.table_flag__get($1, 'nulls_mapped') |
3169 | 3169 |
$_$; |
... | ... | |
3183 | 3183 |
-- |
3184 | 3184 |
|
3185 | 3185 |
CREATE FUNCTION table_nulls_mapped__set(table_ regclass) RETURNS void |
3186 |
LANGUAGE sql STRICT
|
|
3186 |
LANGUAGE sql |
|
3187 | 3187 |
AS $_$ |
3188 | 3188 |
SELECT util.table_flag__set($1, 'nulls_mapped') |
3189 | 3189 |
$_$; |
... | ... | |
3234 | 3234 |
-- |
3235 | 3235 |
|
3236 | 3236 |
CREATE FUNCTION "trim"(table_ regclass, names regclass) RETURNS void |
3237 |
LANGUAGE sql STRICT
|
|
3237 |
LANGUAGE sql |
|
3238 | 3238 |
AS $_$ |
3239 | 3239 |
SELECT util.drop_column(($1, col)) FROM util.added_cols($1, $2) f (col); |
3240 | 3240 |
SELECT NULL::void; -- don't fold away functions called in previous query |
... | ... | |
3316 | 3316 |
-- |
3317 | 3317 |
|
3318 | 3318 |
CREATE FUNCTION try_mk_derived_col(col col_ref, expr text) RETURNS void |
3319 |
LANGUAGE sql STRICT
|
|
3319 |
LANGUAGE sql |
|
3320 | 3320 |
AS $_$ |
3321 | 3321 |
SELECT util.try_create($$SELECT util.mk_derived_col($$||quote_literal($1)||$$, $$||quote_literal($2)||$$)$$) |
3322 | 3322 |
$_$; |
Also available in: Unified diff
schemas/util.sql, vegbien.sql: do not declare any SQL-language functions as STRICT, because this prevents them from being inlined (as documented in the util schema comment). the STRICT qualifier has been preserved where its behavior is necessary, rather than just used for optimization.