pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: tarunt@chisquare.in
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13808: Upsert not working
Date: Wed, 9 Dec 2015 20:18:09 +0100
Message-ID: <20151209191809.GM28762@awork2.anarazel.de> (raw)
In-Reply-To: <20151209090153.872.86659@wrigleys.postgresql.org>
References: <20151209090153.872.86659@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 2015-12-09 09:01:53 +0000, tarunt@chisquare.in wrote:
> drop table daily_deposits;
> create table daily_deposits
> (   id int,
>     fdd timestamp,
>     ldd timestamp,
>     fda double precision,
>     lda double precision
> );
> 
> drop table user_first_last;
> create table user_first_last
> (   UserId int, 
>     FirstLoginDate timestamp,
>     LastLoginDate timestamp,
>     FirstLoginAmt double precision,
>     LastLoginAmt double precision
> );
> 
> 
> INSERT INTO user_first_last AS ufl (UserId,
> FirstLoginDate,LastLoginDate,FirstLoginAmt,LastLoginAmt) 
> select id, fdd,  ldd,fda,  lda 
> from daily_deposits 
> ON CONFLICT (UserId) 
> DO UPDATE  
>   SET FirstLoginAmt = case when excluded.fdd < ufl.FirstLoginDate then
> excluded.fda else ufl.FirstLoginAmt END, 
>       LastLoginAmt = case when excluded.ldd > ufl.LastLoginDate then
> excluded.lda else ufl.LastLoginAmt END,
>       FirstLoginDate = case when excluded.fdd < ufl.FirstLoginDate then
> excluded.fdd else ufl.FirstLoginDate END,
>       LastLoginDate = case when excluded.ldd > ufl.LastLoginDate then
> excluded.ldd else ufl.LastLoginDate END;
> 
> ERROR:  column excluded.fdd does not exist
> LINE 6:   SET FirstLoginAmt = case when excluded.fdd < ufl.FirstLogi...
>                                         ^
> ********** Error **********
> 
> ERROR: column excluded.fdd does not exist
> SQL state: 42703
> Character: 222

'excluded' is about the relation you're inserting to
(i.e. user_first_last / ufl, which doesn't have a fdd column), not about
the table you're selecting from.

Regards,

Andres


-- 
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 (3+ messages)  latest in thread

Message-ID: <20151209191809.GM28762@awork2.anarazel.de>
Permalink:  ../20151209191809.GM28762@awork2.anarazel.de/
Also on:    postgresql.org/message-id/20151209191809.GM28762@awork2.anarazel.de

 · 

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: andres@anarazel.de, tarunt@chisquare.in
  Subject: Re: BUG #13808: Upsert not working
  In-Reply-To: <20151209191809.GM28762@awork2.anarazel.de>
  References: <20151209090153.872.86659@wrigleys.postgresql.org> <20151209191809.GM28762@awork2.anarazel.de>

* 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