pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul Coyne <Paul.Coyne@diridium.com>
To: Peter Geoghegan <pg@bowt.ie>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14609: ON CONSTRAINT (aka UPSERT) code fails when excluded.<columname> used in calculation.
Date: Fri, 31 Mar 2017 22:47:15 +0000
Message-ID: <DA9F4B53-A209-439C-A311-8ED75F3549AB@diridium.com> (raw)
In-Reply-To: <CAH2-Wz=f4fEKwfGz=hZdqx4DNCm3n5w3-zjv7aQrKfAuCwxfgg@mail.gmail.com>
References: <20170331211011.2690.61348@wrigleys.postgresql.org>
	<CAH2-Wz=f4fEKwfGz=hZdqx4DNCm3n5w3-zjv7aQrKfAuCwxfgg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

This does not work (all other code the same for the SP but omitted for brevity):

SET sendingfacility = NULLIF(COALESCE(NULLIF(p_sendingfacility,''),excluded.sendingfacility),'""')

This does work as intended.

SET sendingfacility = NULLIF(COALESCE(NULLIF(p_sendingfacility,''),test.sendingfacility),'""')

It is as if I can’t reference “excluded,sendingfacility” in the calculation.   

The is irrespective of the WHERE clause, but I can remove it as you mention.





On 3/31/17, 4:54 PM, "Peter Geoghegan" <pg@bowt.ie> wrote:

    On Fri, Mar 31, 2017 at 5:10 PM,  <paul.coyne@diridium.com> wrote:
    > Can excluded.variablename be used in a calculation?   It appears to have the
    > value NULL in the formula.
    
    I'm on a flight, and haven't looked at this properly, but I have a
    hard time following the expression in the UPDATE part of your INSERT
    within the plpgsql function. What is this supposed to do?
    
    IF(COALESCE(NULLIF(p_sendingfacility,''),excluded.sendingfacility),'""')
                WHERE excluded.mrn =  p_mrn and excluded.site_code = p_site_code
    
    It's also weird that "WHERE excluded.mrn =  p_mrn" is there, since
    you're proposing that same value (function argument) for insertion in
    the first place (same with site_code).
    
    Are you sure that this isn't just an "IS NULL vs. =" issue?
    
    -- 
    Peter Geoghegan
    


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


view thread (4+ messages)  latest in thread

Message-ID: <DA9F4B53-A209-439C-A311-8ED75F3549AB@diridium.com>
Permalink:  ../DA9F4B53-A209-439C-A311-8ED75F3549AB@diridium.com/
Also on:    postgresql.org/message-id/DA9F4B53-A209-439C-A311-8ED75F3549AB@diridium.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: Paul.Coyne@diridium.com, pg@bowt.ie
  Subject: Re: BUG #14609: ON CONSTRAINT (aka UPSERT) code fails when excluded.<columname> used in calculation.
  In-Reply-To: <DA9F4B53-A209-439C-A311-8ED75F3549AB@diridium.com>
  References: <20170331211011.2690.61348@wrigleys.postgresql.org> <CAH2-Wz=f4fEKwfGz=hZdqx4DNCm3n5w3-zjv7aQrKfAuCwxfgg@mail.gmail.com> <DA9F4B53-A209-439C-A311-8ED75F3549AB@diridium.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox