public inbox for [email protected]  
help / color / mirror / Atom feed
From: Adrian Klaver <[email protected]>
To: pgsql-general <[email protected]>
Subject: Trying to understand pg_get_expr()
Date: Tue, 17 Mar 2026 12:31:43 -0700
Message-ID: <[email protected]> (raw)

Given:

select version();
                   version 

-----------------------------------------------
  PostgreSQL 17.9 (Ubuntu 17.9-1.pgdg24.04+1)

and:

CREATE TABLE default_test (
     id integer,
     fld_1 varchar DEFAULT 'test',
     fld_2 integer DEFAULT 0
);

Then:

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

and:

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, adrelid) = '0';

adrelid    | pg_typeof | pg_get_expr
--------------+-----------+-------------
  default_test | text      | 0


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, adrelid) = 'test';

adrelid | pg_typeof | pg_get_expr
---------+-----------+-------------
(0 rows)

Why does the = 'test' not return anything?

-- 
Adrian Klaver
[email protected]







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]
  Subject: Re: Trying to understand pg_get_expr()
  In-Reply-To: <[email protected]>

* 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