Обсуждение: Unnecessary casts in pg_cast

Поиск
Список
Период
Сортировка

Unnecessary casts in pg_cast

От
Gregory Stark
Дата:
postgres=# select *,(select typname from pg_type where oid = castsource) as source,(select typname from pg_type where
oid= casttarget) as target from pg_cast where castsource = 25 or casttarget = 25;castsource | casttarget | castfunc |
castcontext| source  |  target  
 
------------+------------+----------+-------------+---------+----------        25 |       2205 |     1079 | i
|text    | regclass        25 |       1042 |        0 | i           | text    | bpchar        25 |       1043 |
0| i           | text    | varchar      1042 |         25 |      401 | i           | bpchar  | text      1043 |
25|        0 | i           | varchar | text        18 |         25 |      946 | i           | char    | text        19
|        25 |      406 | i           | name    | text        25 |         18 |      944 | a           | text    | char
     25 |         19 |      407 | i           | text    | name       650 |         25 |      730 | a           | cidr
| text       869 |         25 |      730 | a           | inet    | text        16 |         25 |     2971 | a
|bool    | text       142 |         25 |     2922 | a           | xml     | text        25 |        142 |     2896 | e
        | text    | xml
 
(14 rows)


Why do we need assignment casts from cidr, inet, bool, and xml to text? These
all seem redundant since there's effectively an assignment cast from every
data type to text anyways:


postgres=# delete from pg_cast where casttarget = 25;
DELETE 8

postgres=# insert into t values ('1.0.0.0'::cidr);
INSERT 0 1

postgres=# select * from t;    t      
------------1.0.0.0/32
(1 row)

postgres=# \d t    Table "public.t"Column | Type | Modifiers 
--------+------+-----------t      | text | 

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com Ask me about EnterpriseDB's Slony Replication
support!


Re: Unnecessary casts in pg_cast

От
Tom Lane
Дата:
Gregory Stark <stark@enterprisedb.com> writes:
> Why do we need assignment casts from cidr, inet, bool, and xml to
> text?

Because these cast conversion functions act differently from the datatype
output functions, eg

regression=# select true;bool 
------t
(1 row)

regression=# select true::text;text 
------true
(1 row)

        regards, tom lane