1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-10 14:22:35 +03:00

Remove grotty special-case code in coerce_to_target_type() that

implemented casts to varchar and bpchar using a cast-to-text function.
This is a holdover from before we had pg_cast; it now makes more sense
to just list these casts in pg_cast.  While at it, add pg_cast entries
for the other direction (casts from varchar/bpchar) where feasible.
This commit is contained in:
Tom Lane
2004-03-15 01:13:41 +00:00
parent 64fe1fd239
commit 89ab5c4abf
5 changed files with 101 additions and 53 deletions

View File

@@ -239,11 +239,17 @@ WHERE castsource = casttarget OR castsource = 0 OR casttarget = 0
-- Look for cast functions that don't have the right signature. The
-- argument and result types in pg_proc must be the same as, or binary
-- compatible with, what it says in pg_cast.
-- As a special case, we allow casts from CHAR(n) that use functions
-- declared to take TEXT. This does not pass the binary-coercibility test
-- because CHAR(n)-to-TEXT normally invokes rtrim(). However, the results
-- are the same, so long as the function is one that ignores trailing blanks.
SELECT c.*
FROM pg_cast c, pg_proc p
WHERE c.castfunc = p.oid AND
(p.pronargs <> 1
OR NOT binary_coercible(c.castsource, p.proargtypes[0])
OR NOT (binary_coercible(c.castsource, p.proargtypes[0])
OR (c.castsource = 'character'::regtype AND
p.proargtypes[0] = 'text'::regtype))
OR NOT binary_coercible(p.prorettype, c.casttarget));
castsource | casttarget | castfunc | castcontext
------------+------------+----------+-------------

View File

@@ -196,12 +196,18 @@ WHERE castsource = casttarget OR castsource = 0 OR casttarget = 0
-- Look for cast functions that don't have the right signature. The
-- argument and result types in pg_proc must be the same as, or binary
-- compatible with, what it says in pg_cast.
-- As a special case, we allow casts from CHAR(n) that use functions
-- declared to take TEXT. This does not pass the binary-coercibility test
-- because CHAR(n)-to-TEXT normally invokes rtrim(). However, the results
-- are the same, so long as the function is one that ignores trailing blanks.
SELECT c.*
FROM pg_cast c, pg_proc p
WHERE c.castfunc = p.oid AND
(p.pronargs <> 1
OR NOT binary_coercible(c.castsource, p.proargtypes[0])
OR NOT (binary_coercible(c.castsource, p.proargtypes[0])
OR (c.castsource = 'character'::regtype AND
p.proargtypes[0] = 'text'::regtype))
OR NOT binary_coercible(p.prorettype, c.casttarget));
-- Look for binary compatible casts that do not have the reverse