From: Joe Conway <mail@joeconway.com>
To: Ulrich Goebel <ml@fam-goebel.de>
To: pgsql-general@postgresql.org
Subject: Re: Compare with default value?
Date: Sat, 13 Mar 2021 15:52:51 -0500
Message-ID: <23993869-ba59-0799-5b46-e6f15f64ab88@joeconway.com> (raw)
In-Reply-To: <f36e9ea9-6a08-fc2b-0c77-c0a952db9976@fam-goebel.de>
References: <f36e9ea9-6a08-fc2b-0c77-c0a952db9976@fam-goebel.de>
On 3/13/21 1:05 PM, Ulrich Goebel wrote:
> I would like to get the rows, where a column has the default value,
> similar to:
>
> select id fromt tbl where col = default
>
> Is there a chance?
It isn't pretty, and not all that practical, but for example:
8<--------------------
create table def(id int, f1 text not null default 'foo');
insert into def values(1,'hello'),(2,default),(3,default),(4,'bar');
SELECT *
FROM def
WHERE $$'$$ || f1 || $$'::text$$ =
(SELECT pg_get_expr(d.adbin, d.adrelid, true)
FROM pg_attrdef d
JOIN pg_attribute a on d.adrelid = a.attrelid
AND d.adnum = a.attnum
WHERE a.attrelid = 'def'::regclass
AND a.attname = 'f1');
id | f1
----+-----
2 | foo
3 | foo
(2 rows)
8<--------------------
Hope this helps,
Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: mail@joeconway.com, ml@fam-goebel.de
Subject: Re: Compare with default value?
In-Reply-To: <23993869-ba59-0799-5b46-e6f15f64ab88@joeconway.com>
References: <f36e9ea9-6a08-fc2b-0c77-c0a952db9976@fam-goebel.de> <23993869-ba59-0799-5b46-e6f15f64ab88@joeconway.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox