From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Ulrich Goebel <ml(at)fam-goebel(dot)de>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Compare with default value? |
Date: | 2021-03-13 20:52:51 |
Message-ID: | 23993869-ba59-0799-5b46-e6f15f64ab88@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2021-03-13 20:58:54 | Re: Compare with default value? |
Previous Message | David G. Johnston | 2021-03-13 20:50:49 | Re: Compare with default value? |