Re: BUG #13808: Upsert not working

From: Andres Freund <andres(at)anarazel(dot)de>
To: tarunt(at)chisquare(dot)in
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13808: Upsert not working
Date: 2015-12-09 19:18:09
Message-ID: 20151209191809.GM28762@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2015-12-09 09:01:53 +0000, tarunt(at)chisquare(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Thomas Kellerer 2015-12-09 19:40:17 Re: BUG #13808: Upsert not working
Previous Message filip 2015-12-09 14:07:08 BUG #13810: cursor_to_xml ignores tableforest parameter