Re: Trying to understand pg_get_expr()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Trying to understand pg_get_expr()
Date: 2026-03-17 21:04:50
Message-ID: 566245.1773781490@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> writes:
> adrelid | pg_typeof | pg_get_expr
> --------------+-----------+---------------------------
> default_test | text | 'test'::character varying
> default_test | text | 0

> Why is the second case not?:
> '0'::integer

PG's parser automatically attributes type integer to an unadorned
integer literal, so no cast is necessary there, and pg_get_expr
doesn't add one. But an unadorned string like 'test' does not
have a determinate type (well, it has type "unknown", but that
is an implementation artifact). We emit a cast construct to show
what type the constant was resolved as.

The bigger picture here is that pg_get_expr relies on the same
code that is used for purposes like dumping views. We want the
output to be such that subexpressions of a view will certainly
be parsed as the same type they were interpreted as before.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marcos Pegoraro 2026-03-17 21:12:12 Re: Trying to understand pg_get_expr()
Previous Message Marcos Pegoraro 2026-03-17 20:54:45 Re: Trying to understand pg_get_expr()