mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
Represent type-specific length coercion functions as pg_cast entries,
eliminating the former hard-wired convention about their names. Allow pg_cast entries to represent both type coercion and length coercion in a single step --- this is represented by a function that takes an extra typmod argument, just like a length coercion function. This nicely merges the type and length coercion mechanisms into something at least a little cleaner than we had before. Make use of the single- coercion-step behavior to fix integer-to-bit coercion so that coercing to bit(n) yields the rightmost n bits of the integer instead of the leftmost n bits. This should fix recurrent complaints about the odd behavior of this coercion. Clean up the documentation of the bit string functions, and try to put it where people might actually find it. Also, get rid of the unreliable heuristics in ruleutils.c about whether to display nested coercion steps; instead require parse_coerce.c to label them properly in the first place.
This commit is contained in:
@@ -225,13 +225,28 @@ WHERE p1.prorettype = 'internal'::regtype AND NOT
|
||||
(1 row)
|
||||
|
||||
-- **************** pg_cast ****************
|
||||
-- Look for casts from and to the same type. This is not harmful, but
|
||||
-- useless. Also catch bogus values in pg_cast columns (other than
|
||||
-- cases detected by oidjoins test).
|
||||
-- Catch bogus values in pg_cast columns (other than cases detected by
|
||||
-- oidjoins test).
|
||||
SELECT *
|
||||
FROM pg_cast c
|
||||
WHERE castsource = casttarget OR castsource = 0 OR casttarget = 0
|
||||
OR castcontext NOT IN ('e', 'a', 'i');
|
||||
WHERE castsource = 0 OR casttarget = 0 OR castcontext NOT IN ('e', 'a', 'i');
|
||||
castsource | casttarget | castfunc | castcontext
|
||||
------------+------------+----------+-------------
|
||||
(0 rows)
|
||||
|
||||
-- Look for casts to/from the same type that aren't length coercion functions.
|
||||
-- (We assume they are length coercions if they take multiple arguments.)
|
||||
-- Such entries are not necessarily harmful, but they are useless.
|
||||
SELECT *
|
||||
FROM pg_cast c
|
||||
WHERE castsource = casttarget AND castfunc = 0;
|
||||
castsource | casttarget | castfunc | castcontext
|
||||
------------+------------+----------+-------------
|
||||
(0 rows)
|
||||
|
||||
SELECT c.*
|
||||
FROM pg_cast c, pg_proc p
|
||||
WHERE c.castfunc = p.oid AND p.pronargs < 2 AND castsource = casttarget;
|
||||
castsource | casttarget | castfunc | castcontext
|
||||
------------+------------+----------+-------------
|
||||
(0 rows)
|
||||
@@ -246,7 +261,7 @@ WHERE castsource = casttarget OR castsource = 0 OR casttarget = 0
|
||||
SELECT c.*
|
||||
FROM pg_cast c, pg_proc p
|
||||
WHERE c.castfunc = p.oid AND
|
||||
(p.pronargs <> 1
|
||||
(p.pronargs < 1 OR p.pronargs > 3
|
||||
OR NOT (binary_coercible(c.castsource, p.proargtypes[0])
|
||||
OR (c.castsource = 'character'::regtype AND
|
||||
p.proargtypes[0] = 'text'::regtype))
|
||||
@@ -255,6 +270,15 @@ WHERE c.castfunc = p.oid AND
|
||||
------------+------------+----------+-------------
|
||||
(0 rows)
|
||||
|
||||
SELECT c.*
|
||||
FROM pg_cast c, pg_proc p
|
||||
WHERE c.castfunc = p.oid AND
|
||||
((p.pronargs > 1 AND p.proargtypes[1] != 'int4'::regtype) OR
|
||||
(p.pronargs > 2 AND p.proargtypes[2] != 'bool'::regtype));
|
||||
castsource | casttarget | castfunc | castcontext
|
||||
------------+------------+----------+-------------
|
||||
(0 rows)
|
||||
|
||||
-- Look for binary compatible casts that do not have the reverse
|
||||
-- direction registered as well, or where the reverse direction is not
|
||||
-- also binary compatible. This is legal, but usually not intended.
|
||||
|
||||
@@ -184,14 +184,24 @@ WHERE p1.prorettype = 'internal'::regtype AND NOT
|
||||
|
||||
-- **************** pg_cast ****************
|
||||
|
||||
-- Look for casts from and to the same type. This is not harmful, but
|
||||
-- useless. Also catch bogus values in pg_cast columns (other than
|
||||
-- cases detected by oidjoins test).
|
||||
-- Catch bogus values in pg_cast columns (other than cases detected by
|
||||
-- oidjoins test).
|
||||
|
||||
SELECT *
|
||||
FROM pg_cast c
|
||||
WHERE castsource = casttarget OR castsource = 0 OR casttarget = 0
|
||||
OR castcontext NOT IN ('e', 'a', 'i');
|
||||
WHERE castsource = 0 OR casttarget = 0 OR castcontext NOT IN ('e', 'a', 'i');
|
||||
|
||||
-- Look for casts to/from the same type that aren't length coercion functions.
|
||||
-- (We assume they are length coercions if they take multiple arguments.)
|
||||
-- Such entries are not necessarily harmful, but they are useless.
|
||||
|
||||
SELECT *
|
||||
FROM pg_cast c
|
||||
WHERE castsource = casttarget AND castfunc = 0;
|
||||
|
||||
SELECT c.*
|
||||
FROM pg_cast c, pg_proc p
|
||||
WHERE c.castfunc = p.oid AND p.pronargs < 2 AND castsource = casttarget;
|
||||
|
||||
-- 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
|
||||
@@ -204,12 +214,18 @@ WHERE castsource = casttarget OR castsource = 0 OR casttarget = 0
|
||||
SELECT c.*
|
||||
FROM pg_cast c, pg_proc p
|
||||
WHERE c.castfunc = p.oid AND
|
||||
(p.pronargs <> 1
|
||||
(p.pronargs < 1 OR p.pronargs > 3
|
||||
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));
|
||||
|
||||
SELECT c.*
|
||||
FROM pg_cast c, pg_proc p
|
||||
WHERE c.castfunc = p.oid AND
|
||||
((p.pronargs > 1 AND p.proargtypes[1] != 'int4'::regtype) OR
|
||||
(p.pronargs > 2 AND p.proargtypes[2] != 'bool'::regtype));
|
||||
|
||||
-- Look for binary compatible casts that do not have the reverse
|
||||
-- direction registered as well, or where the reverse direction is not
|
||||
-- also binary compatible. This is legal, but usually not intended.
|
||||
|
||||
Reference in New Issue
Block a user