Re: BUG #13808: Upsert not working - Mailing list pgsql-bugs

From Andres Freund
Subject Re: BUG #13808: Upsert not working
Date
Msg-id 20151209191809.GM28762@awork2.anarazel.de
Whole thread Raw
In response to BUG #13808: Upsert not working  (tarunt@chisquare.in)
List pgsql-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

pgsql-bugs by date:

Previous
From: filip@jirsak.org
Date:
Subject: BUG #13810: cursor_to_xml ignores tableforest parameter
Next
From: Thomas Kellerer
Date:
Subject: Re: BUG #13808: Upsert not working