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

From stan
Subject Re: Can I trigger an action from a coalesce ?
Date
Msg-id 20200222213325.GA22785@panix.com
Whole thread Raw
In response to Re: Can I trigger an action from a coalesce ?  (Christophe Pettus <xof@thebuild.com>)
Responses Re: Can I trigger an action from a coalesce ?
List pgsql-general
On Sat, Feb 22, 2020 at 01:06:57PM -0800, Christophe Pettus wrote:
> 
> 
> > On Feb 22, 2020, at 13:05, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
> > 
> > On 2/22/20 1:02 PM, stan wrote:
> >> I have a case where if a value does not exist, I am going to use a default,
> >> which is easy with coalesce. But I would like to warn the user that a
> >> default has been supplied. The default value is reasonable, and could
> >> actually come from the source table, so I can't just check the value.
> >> I'd like to do a raise NOTICE, if the default portion of the coalesce fires.
> >> Anyone have a good way to accomplish this?
> > 
> > No.
> 
> You can, of course, create a PL/pgSQL function and use that as the default.
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?

Or is there a simpler way?


-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
                        -- Benjamin Franklin



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Replication: slave server has 3x size of production server?
Next
From: Christophe Pettus
Date:
Subject: Re: Can I trigger an action from a coalesce ?