Re: BUG #13808: Upsert not working

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Re: BUG #13808: Upsert not working
Дата
Msg-id 20151209191809.GM28762@awork2.anarazel.de
обсуждение исходный текст
Ответ на BUG #13808: Upsert not working  (tarunt@chisquare.in)
Список 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 по дате отправления:

Предыдущее
От: filip@jirsak.org
Дата:
Сообщение: BUG #13810: cursor_to_xml ignores tableforest parameter
Следующее
От: Thomas Kellerer
Дата:
Сообщение: Re: BUG #13808: Upsert not working