public inbox for [email protected]  
help / color / mirror / Atom feed
From: Marcos Pegoraro <[email protected]>
To: Tom Lane <[email protected]>
Cc: Adrian Klaver <[email protected]>
Cc: pgsql-general <[email protected]>
Subject: Re: Trying to understand pg_get_expr()
Date: Tue, 17 Mar 2026 18:12:12 -0300
Message-ID: <CAB-JLwZ0G43CCePwT0UOZddUV5pi5UWA4uSKi2hk+bzEvZJdKA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<CAB-JLwZdyUfnC047MzV9woskWH2dToNJEudR34AD8WprEn8Cig@mail.gmail.com>
	<[email protected]>
	<CAB-JLwbwKi6q_fG7ByGRJe-L+m9Nx+WHiTP0qhEw7qKzv37QQA@mail.gmail.com>
	<[email protected]>
	<[email protected]>

Em ter., 17 de mar. de 2026 às 18:04, Tom Lane <[email protected]> escreveu:

> 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


Thanks Tom

If your fields default to a string, then all them will have to cast back to
its type when calling that function.

CREATE TABLE default_test (
     id integer,
     fld_1 varchar DEFAULT 'test',
     fld_2 integer DEFAULT '150'::text::integer,
     fld_3 date DEFAULT '2026/05/01',
     fld_4 timestamp DEFAULT '2026/05/01',
     fld_5 text DEFAULT 'x',
     fld_6 boolean DEFAULT 'on'::text::boolean,
     fld_7 int4range DEFAULT '[1,2)',
     fld_8 char DEFAULT '1'
);

regards
Marcos


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Trying to understand pg_get_expr()
  In-Reply-To: <CAB-JLwZ0G43CCePwT0UOZddUV5pi5UWA4uSKi2hk+bzEvZJdKA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox