question about deparsing const node and its typmod

From: "Tao Ma" <feng_eden(at)163(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: question about deparsing const node and its typmod
Date: 2009-03-28 08:05:36
Message-ID: gqklof$2ga3$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Recently, I am reading the postgres codes, and I have a question about the
deparsing some expressions which is contains Const node. The following SQL
will retrieve the definition stored by postgres database for table "t":

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)

Postgres will emit a implicit coercion for the default value of c1 column
before the definition node can be stored in system catalog pg_attrdef.
To retrieve a human-readable definition for the default value, pg_get_expr()
will call get_func_expr() to display the default value. get_func_expr()
will omit the implicit function and return the first argument barely. The
default value for column c2 is pretty than the default value for column c1,
so I am courious about is there any possibility to make the default value
for c1 look like the default value for c2.

If we do not concern the compatible with old system, is it possible to
modify the function transformExpr() or something else to archieve the the
'pretty'(may be not pretty at all for someone) format? It seems assign the
correct typmod to Const node during transform phase is possible, but most
of time it is meaningless. typmod plays an important role during the
process of coercion decision, it seems the coercion will absence iff the
type and typmod is same.

Thanks in advance,
Tao Ma

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Devrim GÜNDÜZ 2009-03-28 09:02:31 New shapshot RPMs (Mar 27, 2009) are ready for testing
Previous Message Simon Riggs 2009-03-28 07:20:30 Re: Should SET ROLE inherit config params?