Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit767982e

Browse files
committed
Convert built-in SQL-language functions to SQL-standard-body style.
Adopt the new pre-parsed representation for all built-in andinformation_schema SQL-language functions, except for a smallnumber that can't presently be converted because they havepolymorphic arguments.This eliminates residual hazards around search-path safety ofthese functions, and might provide some small performance benefitsby reducing parsing costs. It seems useful also to provide moretest coverage for the SQL-standard-body feature.Discussion:https://postgr.es/m/3956760.1618529139@sss.pgh.pa.us
1 parente809493 commit767982e

File tree

4 files changed

+402
-113
lines changed

4 files changed

+402
-113
lines changed

‎src/backend/catalog/information_schema.sql

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ SET search_path TO information_schema;
4343
CREATEFUNCTION_pg_expandarray(IN anyarray, OUT x anyelement, OUT nint)
4444
RETURNS SETOF RECORD
4545
LANGUAGE sql STRICT IMMUTABLE PARALLEL SAFE
46-
AS'select $1[s], s - pg_catalog.array_lower($1,1) + 1
46+
AS'select $1[s],
47+
s operator(pg_catalog.-) pg_catalog.array_lower($1,1) operator(pg_catalog.+) 1
4748
from pg_catalog.generate_series(pg_catalog.array_lower($1,1),
4849
pg_catalog.array_upper($1,1),
4950
1) as g(s)';
@@ -52,28 +53,26 @@ CREATE FUNCTION _pg_expandarray(IN anyarray, OUT x anyelement, OUT n int)
5253
* column's position in the index (NULL if not there)*/
5354
CREATEFUNCTION_pg_index_position(oid,smallint) RETURNSint
5455
LANGUAGE sql STRICT STABLE
55-
AS $$
56+
BEGIN ATOMIC
5657
SELECT (ss.a).nFROM
5758
(SELECTinformation_schema._pg_expandarray(indkey)AS a
5859
FROMpg_catalog.pg_indexWHERE indexrelid= $1) ss
5960
WHERE (ss.a).x= $2;
60-
$$;
61+
END;
6162

6263
CREATEFUNCTION_pg_truetypid(pg_attribute, pg_type) RETURNSoid
6364
LANGUAGE sql
6465
IMMUTABLE
6566
PARALLEL SAFE
6667
RETURNSNULLONNULL INPUT
67-
AS
68-
$$SELECT CASE WHEN $2.typtype='d' THEN $2.typbasetype ELSE $1.atttypid END$$;
68+
RETURN CASE WHEN $2.typtype='d' THEN $2.typbasetype ELSE $1.atttypid END;
6969

7070
CREATEFUNCTION_pg_truetypmod(pg_attribute, pg_type) RETURNS int4
7171
LANGUAGE sql
7272
IMMUTABLE
7373
PARALLEL SAFE
7474
RETURNSNULLONNULL INPUT
75-
AS
76-
$$SELECT CASE WHEN $2.typtype='d' THEN $2.typtypmod ELSE $1.atttypmod END$$;
75+
RETURN CASE WHEN $2.typtype='d' THEN $2.typtypmod ELSE $1.atttypmod END;
7776

7877
-- these functions encapsulate knowledge about the encoding of typmod:
7978

@@ -82,40 +81,37 @@ CREATE FUNCTION _pg_char_max_length(typid oid, typmod int4) RETURNS integer
8281
IMMUTABLE
8382
PARALLEL SAFE
8483
RETURNSNULLONNULL INPUT
85-
AS
86-
$$SELECT
84+
RETURN
8785
CASE WHEN $2=-1/* default typmod*/
8886
THENnull
8987
WHEN $1IN (1042,1043)/* char, varchar*/
9088
THEN $2-4
9189
WHEN $1IN (1560,1562)/* bit, varbit*/
9290
THEN $2
9391
ELSEnull
94-
END$$;
92+
END;
9593

9694
CREATEFUNCTION_pg_char_octet_length(typidoid, typmod int4) RETURNSinteger
9795
LANGUAGE sql
9896
IMMUTABLE
9997
PARALLEL SAFE
10098
RETURNSNULLONNULL INPUT
101-
AS
102-
$$SELECT
99+
RETURN
103100
CASE WHEN $1IN (25,1042,1043)/* text, char, varchar*/
104101
THEN CASE WHEN $2=-1/* default typmod*/
105102
THEN CAST(2^30ASinteger)
106103
ELSEinformation_schema._pg_char_max_length($1, $2)*
107104
pg_catalog.pg_encoding_max_length((SELECT encodingFROMpg_catalog.pg_databaseWHERE datname=pg_catalog.current_database()))
108105
END
109106
ELSEnull
110-
END$$;
107+
END;
111108

112109
CREATEFUNCTION_pg_numeric_precision(typidoid, typmod int4) RETURNSinteger
113110
LANGUAGE sql
114111
IMMUTABLE
115112
PARALLEL SAFE
116113
RETURNSNULLONNULL INPUT
117-
AS
118-
$$SELECT
114+
RETURN
119115
CASE $1
120116
WHEN21/*int2*/ THEN16
121117
WHEN23/*int4*/ THEN32
@@ -128,63 +124,59 @@ $$SELECT
128124
WHEN700/*float4*/ THEN24/*FLT_MANT_DIG*/
129125
WHEN701/*float8*/ THEN53/*DBL_MANT_DIG*/
130126
ELSEnull
131-
END$$;
127+
END;
132128

133129
CREATEFUNCTION_pg_numeric_precision_radix(typidoid, typmod int4) RETURNSinteger
134130
LANGUAGE sql
135131
IMMUTABLE
136132
PARALLEL SAFE
137133
RETURNSNULLONNULL INPUT
138-
AS
139-
$$SELECT
134+
RETURN
140135
CASE WHEN $1IN (21,23,20,700,701) THEN2
141136
WHEN $1IN (1700) THEN10
142137
ELSEnull
143-
END$$;
138+
END;
144139

145140
CREATEFUNCTION_pg_numeric_scale(typidoid, typmod int4) RETURNSinteger
146141
LANGUAGE sql
147142
IMMUTABLE
148143
PARALLEL SAFE
149144
RETURNSNULLONNULL INPUT
150-
AS
151-
$$SELECT
145+
RETURN
152146
CASE WHEN $1IN (21,23,20) THEN0
153147
WHEN $1IN (1700) THEN
154148
CASE WHEN $2=-1
155149
THENnull
156150
ELSE ($2-4) &65535
157151
END
158152
ELSEnull
159-
END$$;
153+
END;
160154

161155
CREATEFUNCTION_pg_datetime_precision(typidoid, typmod int4) RETURNSinteger
162156
LANGUAGE sql
163157
IMMUTABLE
164158
PARALLEL SAFE
165159
RETURNSNULLONNULL INPUT
166-
AS
167-
$$SELECT
160+
RETURN
168161
CASE WHEN $1IN (1082)/* date*/
169162
THEN0
170163
WHEN $1IN (1083,1114,1184,1266)/* time, timestamp, same + tz*/
171164
THEN CASE WHEN $2<0 THEN6 ELSE $2 END
172165
WHEN $1IN (1186)/* interval*/
173166
THEN CASE WHEN $2<0OR $2 &65535=65535 THEN6 ELSE $2 &65535 END
174167
ELSEnull
175-
END$$;
168+
END;
176169

177170
CREATEFUNCTION_pg_interval_type(typidoid, mod int4) RETURNStext
178171
LANGUAGE sql
179172
IMMUTABLE
180173
PARALLEL SAFE
181174
RETURNSNULLONNULL INPUT
182-
AS
183-
$$SELECT
175+
RETURN
184176
CASE WHEN $1IN (1186)/* interval*/
185177
THENpg_catalog.upper(substring(pg_catalog.format_type($1, $2) similar'interval[()0-9]* #"%#"' escape'#'))
186178
ELSEnull
187-
END$$;
179+
END;
188180

189181

190182
-- 5.2 INFORMATION_SCHEMA_CATALOG_NAME view appears later.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp