public inbox for [email protected]
help / color / mirror / Atom feedRe: Trying to understand pg_get_expr()
4+ messages / 2 participants
[nested] [flat]
* Re: Trying to understand pg_get_expr()
@ 2026-03-17 20:19 Adrian Klaver <[email protected]>
2026-03-17 20:26 ` Re: Trying to understand pg_get_expr() Marcos Pegoraro <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Adrian Klaver @ 2026-03-17 20:19 UTC (permalink / raw)
To: Marcos Pegoraro <[email protected]>; +Cc: pgsql-general
On 3/17/26 1:08 PM, Marcos Pegoraro wrote:
> Em ter., 17 de mar. de 2026 às 16:31, Adrian Klaver
> <[email protected] <mailto:[email protected]>> escreveu:
>
> Why does the = 'test' not return anything?
>
>
> for me pg_get_expr(adbin, adrelid) returns 'test'::character varying
> so it differs from 'test'
I should have indicated I tried casting:
SELECT
adrelid::regclass,
pg_typeof(pg_get_expr(adbin, adrelid)),
pg_get_expr(adbin, adrelid)
FROM
pg_attrdef
WHERE
adrelid = 'default_test'::regclass
AND pg_get_expr(adbin, 0) = 'test'::character varying;
adrelid | pg_typeof | pg_get_expr
---------+-----------+-------------
I also tried other combinations of casting both sides of "=" and it
still did not work.
>
> regards
> Marcos
--
Adrian Klaver
[email protected]
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Trying to understand pg_get_expr()
2026-03-17 20:19 Re: Trying to understand pg_get_expr() Adrian Klaver <[email protected]>
@ 2026-03-17 20:26 ` Marcos Pegoraro <[email protected]>
2026-03-17 20:36 ` Re: Trying to understand pg_get_expr() Adrian Klaver <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Marcos Pegoraro @ 2026-03-17 20:26 UTC (permalink / raw)
To: Adrian Klaver <[email protected]>; +Cc: pgsql-general
Em ter., 17 de mar. de 2026 às 17:19, Adrian Klaver <
[email protected]> escreveu:
> I also tried other combinations of casting both sides of "=" and it
> still did not work.
>
"'test'::character varying" is the result of that function, not type of test
This should work
AND pg_get_expr(adbin, adrelid) = $$'test'::character varying$$;
regards
Marcos
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Trying to understand pg_get_expr()
2026-03-17 20:19 Re: Trying to understand pg_get_expr() Adrian Klaver <[email protected]>
2026-03-17 20:26 ` Re: Trying to understand pg_get_expr() Marcos Pegoraro <[email protected]>
@ 2026-03-17 20:36 ` Adrian Klaver <[email protected]>
2026-03-17 20:54 ` Re: Trying to understand pg_get_expr() Marcos Pegoraro <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Adrian Klaver @ 2026-03-17 20:36 UTC (permalink / raw)
To: Marcos Pegoraro <[email protected]>; +Cc: pgsql-general
On 3/17/26 1:26 PM, Marcos Pegoraro wrote:
> Em ter., 17 de mar. de 2026 às 17:19, Adrian Klaver
> <[email protected] <mailto:[email protected]>> escreveu:
>
> I also tried other combinations of casting both sides of "=" and it
> still did not work.
>
>
> "'test'::character varying" is the result of that function, not type of test
> This should work
> AND pg_get_expr(adbin, adrelid) = $$'test'::character varying$$;
Yeah that worked.
It begs the question then, in:
SELECT
adrelid::regclass,
pg_typeof(pg_get_expr(adbin, adrelid)),
pg_get_expr(adbin, adrelid)
FROM
pg_attrdef
WHERE
adrelid = 'default_test'::regclass;
adrelid | pg_typeof | pg_get_expr
--------------+-----------+---------------------------
default_test | text | 'test'::character varying
default_test | text | 0
Why is the second case not?:
'0'::integer
>
> regards
> Marcos
>
--
Adrian Klaver
[email protected]
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Trying to understand pg_get_expr()
2026-03-17 20:19 Re: Trying to understand pg_get_expr() Adrian Klaver <[email protected]>
2026-03-17 20:26 ` Re: Trying to understand pg_get_expr() Marcos Pegoraro <[email protected]>
2026-03-17 20:36 ` Re: Trying to understand pg_get_expr() Adrian Klaver <[email protected]>
@ 2026-03-17 20:54 ` Marcos Pegoraro <[email protected]>
0 siblings, 0 replies; 4+ messages in thread
From: Marcos Pegoraro @ 2026-03-17 20:54 UTC (permalink / raw)
To: Adrian Klaver <[email protected]>; +Cc: pgsql-general
Em ter., 17 de mar. de 2026 às 17:36, Adrian Klaver <
[email protected]> escreveu:
> Why is the second case not?:
>
I don't know, but you can see that it's not only for integers
CREATE TABLE default_test (
id integer,
fld_1 varchar DEFAULT 'test',
fld_2 integer DEFAULT 0,
fld_3 date DEFAULT Current_Date,
fld_4 timestamp DEFAULT Current_Timestamp,
fld_5 text DEFAULT 'x',
fld_6 boolean DEFAULT 'on',
fld_7 int4range DEFAULT '[1,2)',
fld_8 char DEFAULT '1'
);
SELECT
atttypid::regtype,
pg_get_expr(adbin, adrelid)
FROM pg_class c inner join
pg_attribute a on c.oid = attrelid
inner join pg_attrdef d on c.oid = d.adrelid and adnum = attnum
WHERE
relname = 'default_test' and attnum > 0;
regards
Marcs
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2026-03-17 20:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-17 20:19 Re: Trying to understand pg_get_expr() Adrian Klaver <[email protected]>
2026-03-17 20:26 ` Marcos Pegoraro <[email protected]>
2026-03-17 20:36 ` Adrian Klaver <[email protected]>
2026-03-17 20:54 ` Marcos Pegoraro <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox