Re: Can I trigger an action from a coalesce ? - Mailing list pgsql-general

From Christophe Pettus
Subject Re: Can I trigger an action from a coalesce ?
Date
Msg-id 982511F6-2957-43EE-8A28-3A5541B56ADF@thebuild.com
Whole thread Raw
In response to Re: Can I trigger an action from a coalesce ?  (stan <stanb@panix.com>)
Responses Re: Can I trigger an action from a coalesce ?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general

> On Feb 22, 2020, at 13:33, stan <stanb@panix.com> wrote:
> I suppose you are suggesting that the function try the original SELECT, and
> if it returns a NULL then retun the default AND do the raise NOTICE?

Something like this:

create function supply_default() returns int as $$
begin
   raise notice 'Supplied default';
   return 1;
end;
$$ immutable language plpgsql;

xof=# create table t ( i integer default supply_default(), t text );
CREATE TABLE
xof=# insert into t(i, t) values (2, 'text');
INSERT 0 1
xof=# insert into t(t) values ('text');
NOTICE:  Supplied default
INSERT 0 1

--
-- Christophe Pettus
   xof@thebuild.com




pgsql-general by date:

Previous
From: stan
Date:
Subject: Re: Can I trigger an action from a coalesce ?
Next
From: Tom Lane
Date:
Subject: Re: Can I trigger an action from a coalesce ?