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