diff options
author | Tom Lane | 2021-12-11 19:10:51 +0000 |
---|---|---|
committer | Tom Lane | 2021-12-11 19:10:51 +0000 |
commit | 07eee5a0dc642d26f44d65c4e6263304208e8583 (patch) | |
tree | d1e1dfa452a2e7d032b2b6226fe38478139927f3 /contrib | |
parent | fe60b67250a31cd1ac2a4882f12e199e30abd316 (diff) |
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 only
store one byte. (In our actual usage, it's more like an enum.)
This choice now seems wrong in view of the special heuristics
that parse_func.c and parse_coerce.c have for TYPCATEGORY_STRING:
it's not a great idea for "char" to have those preferential casting
behaviors.
Worse than that, recent patches inventing special-purpose types
like pg_node_tree have assigned typcategory S to those types,
meaning they also get preferential casting treatment that's designed
on the assumption that they can hold arbitrary text.
To fix, invent a new category TYPCATEGORY_INTERNAL for internal-use
types, and assign that to all these types. I used code 'Z' for
lack of a better idea ('I' was already taken).
This change breaks one query in psql/describe.c, which now needs to
explicitly cast a catalog "char" column to text before concatenating
it with an undecorated literal. Also, a test case in contrib/citext
now needs an explicit cast to convert citext to "char". Since the
point of this change is to not have "char" be a surprisingly-available
cast target, these breakages seem OK.
Per report from Ian Campbell.
Discussion: https://postgr.es/m/2216388.1638480141@sss.pgh.pa.us
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/citext/expected/citext.out | 7 | ||||
-rw-r--r-- | contrib/citext/expected/citext_1.out | 7 | ||||
-rw-r--r-- | contrib/citext/sql/citext.sql | 3 |
3 files changed, 14 insertions, 3 deletions
diff --git a/contrib/citext/expected/citext.out b/contrib/citext/expected/citext.out index ec99aaed5d..3bac0534fb 100644 --- a/contrib/citext/expected/citext.out +++ b/contrib/citext/expected/citext.out @@ -1089,7 +1089,12 @@ INSERT INTO caster (char) VALUES ('f'::citext); INSERT INTO caster (citext) VALUES ('f'::char); INSERT INTO caster (chr) VALUES ('f'::text); INSERT INTO caster (text) VALUES ('f'::"char"); -INSERT INTO caster (chr) VALUES ('f'::citext); +INSERT INTO caster (chr) VALUES ('f'::citext); -- requires cast +ERROR: column "chr" is of type "char" but expression is of type citext +LINE 1: INSERT INTO caster (chr) VALUES ('f'::citext); + ^ +HINT: You will need to rewrite or cast the expression. +INSERT INTO caster (chr) VALUES ('f'::citext::text); INSERT INTO caster (citext) VALUES ('f'::"char"); INSERT INTO caster (name) VALUES ('foo'::text); INSERT INTO caster (text) VALUES ('foo'::name); diff --git a/contrib/citext/expected/citext_1.out b/contrib/citext/expected/citext_1.out index 75fd08b7cc..57fc863f7a 100644 --- a/contrib/citext/expected/citext_1.out +++ b/contrib/citext/expected/citext_1.out @@ -1089,7 +1089,12 @@ INSERT INTO caster (char) VALUES ('f'::citext); INSERT INTO caster (citext) VALUES ('f'::char); INSERT INTO caster (chr) VALUES ('f'::text); INSERT INTO caster (text) VALUES ('f'::"char"); -INSERT INTO caster (chr) VALUES ('f'::citext); +INSERT INTO caster (chr) VALUES ('f'::citext); -- requires cast +ERROR: column "chr" is of type "char" but expression is of type citext +LINE 1: INSERT INTO caster (chr) VALUES ('f'::citext); + ^ +HINT: You will need to rewrite or cast the expression. +INSERT INTO caster (chr) VALUES ('f'::citext::text); INSERT INTO caster (citext) VALUES ('f'::"char"); INSERT INTO caster (name) VALUES ('foo'::text); INSERT INTO caster (text) VALUES ('foo'::name); diff --git a/contrib/citext/sql/citext.sql b/contrib/citext/sql/citext.sql index 10232f5a9f..55fb1d11a6 100644 --- a/contrib/citext/sql/citext.sql +++ b/contrib/citext/sql/citext.sql @@ -361,7 +361,8 @@ INSERT INTO caster (citext) VALUES ('f'::char); INSERT INTO caster (chr) VALUES ('f'::text); INSERT INTO caster (text) VALUES ('f'::"char"); -INSERT INTO caster (chr) VALUES ('f'::citext); +INSERT INTO caster (chr) VALUES ('f'::citext); -- requires cast +INSERT INTO caster (chr) VALUES ('f'::citext::text); INSERT INTO caster (citext) VALUES ('f'::"char"); INSERT INTO caster (name) VALUES ('foo'::text); |