Re: question about deparsing const node and its typmod - Mailing list pgsql-hackers

From Tom Lane
Subject Re: question about deparsing const node and its typmod
Date
Msg-id 18655.1238258851@sss.pgh.pa.us
Whole thread Raw
In response to question about deparsing const node and its typmod  ("Tao Ma" <feng_eden@163.com>)
List pgsql-hackers
"Tao Ma" <feng_eden@163.com> writes:
> CREATE TABLE "t" (c1 CHAR(5) DEFAULT 'abc',
>                   c2 CHAR(5) DEFAULT 'abc'::CHAR(5));

> SELECT pg_get_expr(adbin, adrelid)
>     FROM pg_attrdef
>     WHERE adrelid = (SELECT oid FROM pg_class WHERE relname = 't');

>      pg_get_expr
> ---------------------
>  'abc'::bpchar
>  'abc'::character(5)
> (2 rows)

> so I am courious about is there any possibility to make the default value
> for c1 look like the default value for c2.

That behavior is very carefully chosen to reproduce the actual semantics
of the expression in various contexts.  We can't change it just to make
it "look prettier".

If you check the CVS history of ruleutils.c to see when that logic got
changed, you should be able to locate pgsql-hackers discussions that
worked out what the behavior has to be.  I seem to remember that the
most recent iteration had to do with making sure that ALTER COLUMN TYPE
had unsurprising side-effects on the column's default.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: 8.4 open items list
Next
From: Tom Lane
Date:
Subject: Re: [COMMITTERS] pgsql: Temporarily (I hope) disable flattening of IN/EXISTS sublinks