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

Commit07eee5a

Browse files
committed
Create a new type category for "internal use" types.
Historically we've put type "char" into the S (String) typcategory,although calling it a string is a stretch considering it can onlystore one byte. (In our actual usage, it's more like an enum.)This choice now seems wrong in view of the special heuristicsthat parse_func.c and parse_coerce.c have for TYPCATEGORY_STRING:it's not a great idea for "char" to have those preferential castingbehaviors.Worse than that, recent patches inventing special-purpose typeslike pg_node_tree have assigned typcategory S to those types,meaning they also get preferential casting treatment that's designedon the assumption that they can hold arbitrary text.To fix, invent a new category TYPCATEGORY_INTERNAL for internal-usetypes, and assign that to all these types. I used code 'Z' forlack of a better idea ('I' was already taken).This change breaks one query in psql/describe.c, which now needs toexplicitly cast a catalog "char" column to text before concatenatingit with an undecorated literal. Also, a test case in contrib/citextnow needs an explicit cast to convert citext to "char". Since thepoint of this change is to not have "char" be a surprisingly-availablecast target, these breakages seem OK.Per report from Ian Campbell.Discussion:https://postgr.es/m/2216388.1638480141@sss.pgh.pa.us
1 parentfe60b67 commit07eee5a

File tree

8 files changed

+29
-13
lines changed

8 files changed

+29
-13
lines changed

‎contrib/citext/expected/citext.out

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,12 @@ INSERT INTO caster (char) VALUES ('f'::citext);
10891089
INSERT INTO caster (citext) VALUES ('f'::char);
10901090
INSERT INTO caster (chr) VALUES ('f'::text);
10911091
INSERT INTO caster (text) VALUES ('f'::"char");
1092-
INSERT INTO caster (chr) VALUES ('f'::citext);
1092+
INSERT INTO caster (chr) VALUES ('f'::citext); -- requires cast
1093+
ERROR: column "chr" is of type "char" but expression is of type citext
1094+
LINE 1: INSERT INTO caster (chr) VALUES ('f'::citext);
1095+
^
1096+
HINT: You will need to rewrite or cast the expression.
1097+
INSERT INTO caster (chr) VALUES ('f'::citext::text);
10931098
INSERT INTO caster (citext) VALUES ('f'::"char");
10941099
INSERT INTO caster (name) VALUES ('foo'::text);
10951100
INSERT INTO caster (text) VALUES ('foo'::name);

‎contrib/citext/expected/citext_1.out

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,12 @@ INSERT INTO caster (char) VALUES ('f'::citext);
10891089
INSERT INTO caster (citext) VALUES ('f'::char);
10901090
INSERT INTO caster (chr) VALUES ('f'::text);
10911091
INSERT INTO caster (text) VALUES ('f'::"char");
1092-
INSERT INTO caster (chr) VALUES ('f'::citext);
1092+
INSERT INTO caster (chr) VALUES ('f'::citext); -- requires cast
1093+
ERROR: column "chr" is of type "char" but expression is of type citext
1094+
LINE 1: INSERT INTO caster (chr) VALUES ('f'::citext);
1095+
^
1096+
HINT: You will need to rewrite or cast the expression.
1097+
INSERT INTO caster (chr) VALUES ('f'::citext::text);
10931098
INSERT INTO caster (citext) VALUES ('f'::"char");
10941099
INSERT INTO caster (name) VALUES ('foo'::text);
10951100
INSERT INTO caster (text) VALUES ('foo'::name);

‎contrib/citext/sql/citext.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ INSERT INTO caster (citext) VALUES ('f'::char);
361361

362362
INSERT INTO caster (chr)VALUES ('f'::text);
363363
INSERT INTO caster (text)VALUES ('f'::"char");
364-
INSERT INTO caster (chr)VALUES ('f'::citext);
364+
INSERT INTO caster (chr)VALUES ('f'::citext);-- requires cast
365+
INSERT INTO caster (chr)VALUES ('f'::citext::text);
365366
INSERT INTO caster (citext)VALUES ('f'::"char");
366367

367368
INSERT INTO caster (name)VALUES ('foo'::text);

‎doc/src/sgml/catalogs.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9317,6 +9317,10 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
93179317
<entry><literal>X</literal></entry>
93189318
<entry><type>unknown</type> type</entry>
93199319
</row>
9320+
<row>
9321+
<entry><literal>Z</literal></entry>
9322+
<entry>Internal-use types</entry>
9323+
</row>
93209324
</tbody>
93219325
</tgroup>
93229326
</table>

‎src/bin/psql/describe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ permissionsList(const char *pattern)
11421142
",\n pg_catalog.array_to_string(ARRAY(\n"
11431143
" SELECT polname\n"
11441144
" || CASE WHEN polcmd != '*' THEN\n"
1145-
" E' (' || polcmd || E'):'\n"
1145+
" E' (' || polcmd::pg_catalog.text || E'):'\n"
11461146
" ELSE E':'\n"
11471147
" END\n"
11481148
" || CASE WHEN polqual IS NOT NULL THEN\n"
@@ -1176,7 +1176,7 @@ permissionsList(const char *pattern)
11761176
" E' (RESTRICTIVE)'\n"
11771177
" ELSE '' END\n"
11781178
" || CASE WHEN polcmd != '*' THEN\n"
1179-
" E' (' || polcmd || E'):'\n"
1179+
" E' (' || polcmd::pg_catalog.text || E'):'\n"
11801180
" ELSE E':'\n"
11811181
" END\n"
11821182
" || CASE WHEN polqual IS NOT NULL THEN\n"

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO202112081
56+
#defineCATALOG_VERSION_NO202112111
5757

5858
#endif

‎src/include/catalog/pg_type.dat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
typinput => 'byteain', typoutput => 'byteaout', typreceive => 'bytearecv',
4343
typsend => 'byteasend', typalign => 'i', typstorage => 'x' },
4444
{ oid => '18', array_type_oid => '1002', descr => 'single character',
45-
typname => 'char', typlen => '1', typbyval => 't', typcategory => 'S',
45+
typname => 'char', typlen => '1', typbyval => 't', typcategory => 'Z',
4646
typinput => 'charin', typoutput => 'charout', typreceive => 'charrecv',
4747
typsend => 'charsend', typalign => 'c' },
4848
{ oid => '19', array_type_oid => '1003',
@@ -145,24 +145,24 @@
145145
typsend => 'xml_send', typalign => 'i', typstorage => 'x' },
146146
{ oid => '194', descr => 'string representing an internal node tree',
147147
typname => 'pg_node_tree', typlen => '-1', typbyval => 'f',
148-
typcategory => 'S', typinput => 'pg_node_tree_in',
148+
typcategory => 'Z', typinput => 'pg_node_tree_in',
149149
typoutput => 'pg_node_tree_out', typreceive => 'pg_node_tree_recv',
150150
typsend => 'pg_node_tree_send', typalign => 'i', typstorage => 'x',
151151
typcollation => 'default' },
152152
{ oid => '3361', descr => 'multivariate ndistinct coefficients',
153153
typname => 'pg_ndistinct', typlen => '-1', typbyval => 'f',
154-
typcategory => 'S', typinput => 'pg_ndistinct_in',
154+
typcategory => 'Z', typinput => 'pg_ndistinct_in',
155155
typoutput => 'pg_ndistinct_out', typreceive => 'pg_ndistinct_recv',
156156
typsend => 'pg_ndistinct_send', typalign => 'i', typstorage => 'x',
157157
typcollation => 'default' },
158158
{ oid => '3402', descr => 'multivariate dependencies',
159159
typname => 'pg_dependencies', typlen => '-1', typbyval => 'f',
160-
typcategory => 'S', typinput => 'pg_dependencies_in',
160+
typcategory => 'Z', typinput => 'pg_dependencies_in',
161161
typoutput => 'pg_dependencies_out', typreceive => 'pg_dependencies_recv',
162162
typsend => 'pg_dependencies_send', typalign => 'i', typstorage => 'x',
163163
typcollation => 'default' },
164164
{ oid => '5017', descr => 'multivariate MCV list',
165-
typname => 'pg_mcv_list', typlen => '-1', typbyval => 'f', typcategory => 'S',
165+
typname => 'pg_mcv_list', typlen => '-1', typbyval => 'f', typcategory => 'Z',
166166
typinput => 'pg_mcv_list_in', typoutput => 'pg_mcv_list_out',
167167
typreceive => 'pg_mcv_list_recv', typsend => 'pg_mcv_list_send',
168168
typalign => 'i', typstorage => 'x', typcollation => 'default' },
@@ -681,13 +681,13 @@
681681
typalign => 'd', typstorage => 'x' },
682682
{ oid => '4600', descr => 'BRIN bloom summary',
683683
typname => 'pg_brin_bloom_summary', typlen => '-1', typbyval => 'f',
684-
typcategory => 'S', typinput => 'brin_bloom_summary_in',
684+
typcategory => 'Z', typinput => 'brin_bloom_summary_in',
685685
typoutput => 'brin_bloom_summary_out',
686686
typreceive => 'brin_bloom_summary_recv', typsend => 'brin_bloom_summary_send',
687687
typalign => 'i', typstorage => 'x', typcollation => 'default' },
688688
{ oid => '4601', descr => 'BRIN minmax-multi summary',
689689
typname => 'pg_brin_minmax_multi_summary', typlen => '-1', typbyval => 'f',
690-
typcategory => 'S', typinput => 'brin_minmax_multi_summary_in',
690+
typcategory => 'Z', typinput => 'brin_minmax_multi_summary_in',
691691
typoutput => 'brin_minmax_multi_summary_out',
692692
typreceive => 'brin_minmax_multi_summary_recv',
693693
typsend => 'brin_minmax_multi_summary_send', typalign => 'i',

‎src/include/catalog/pg_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ DECLARE_UNIQUE_INDEX(pg_type_typname_nsp_index, 2704, TypeNameNspIndexId, on pg_
294294
#defineTYPCATEGORY_USER'U'
295295
#defineTYPCATEGORY_BITSTRING'V'/* er ... "varbit"? */
296296
#defineTYPCATEGORY_UNKNOWN'X'
297+
#defineTYPCATEGORY_INTERNAL'Z'
297298

298299
#defineTYPALIGN_CHAR'c'/* char alignment (i.e. unaligned) */
299300
#defineTYPALIGN_SHORT's'/* short alignment (typically 2 bytes) */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp