Re: Can I trigger an action from a coalesce ?

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: stan <stanb(at)panix(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Can I trigger an action from a coalesce ?
Date: 2020-02-22 21:46:56
Message-ID: 982511F6-2957-43EE-8A28-3A5541B56ADF@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Feb 22, 2020, at 13:33, stan <stanb(at)panix(dot)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(at)thebuild(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2020-02-22 22:02:33 Re: Can I trigger an action from a coalesce ?
Previous Message stan 2020-02-22 21:33:25 Re: Can I trigger an action from a coalesce ?