Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5cOy-0005VI-Qg for pgsql-general@arkaria.postgresql.org; Sat, 22 Feb 2020 21:33:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j5cOw-0003EC-4X for pgsql-general@arkaria.postgresql.org; Sat, 22 Feb 2020 21:33:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5cOv-0003E4-NI for pgsql-general@lists.postgresql.org; Sat, 22 Feb 2020 21:33:29 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j5cOt-0006uJ-3P for pgsql-general@lists.postgresql.org; Sat, 22 Feb 2020 21:33:28 +0000 Received: from panix5.panix.com (panix5.panix.com [166.84.1.5]) by mailbackend.panix.com (Postfix) with ESMTP id 48Q1lp0493zx0h; Sat, 22 Feb 2020 16:33:25 -0500 (EST) Received: by panix5.panix.com (Postfix, from userid 17622) id 48Q1ln5Y99zfYm; Sat, 22 Feb 2020 16:33:25 -0500 (EST) Date: Sat, 22 Feb 2020 16:33:25 -0500 From: stan To: Christophe Pettus Cc: pgsql-general@lists.postgresql.org Subject: Re: Can I trigger an action from a coalesce ? Message-ID: <20200222213325.GA22785@panix.com> References: <20200222210206.GA17445@panix.com> <35c60adc-3f02-13ad-a4a6-48642a1185d8@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Editor: gVim List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Feb 22, 2020 at 01:06:57PM -0800, Christophe Pettus wrote: > > > > On Feb 22, 2020, at 13:05, Adrian Klaver 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