BUG #14327: UPSERT requires full path to column

Started by Egor Puginover 9 years ago3 messagesbugs
Jump to latest
#1Egor Pugin
egor.pugin@gmail.com

The following bug has been logged on the website:

Bug reference: 14327
Logged by: Egor Pugin
Email address: egor.pugin@gmail.com
PostgreSQL version: 9.5.4
Operating system: win10
Description:

Hi,

I've noticed upsert query won't work if I do not write 'schema.TABLE.column'
instead of simple 'column' in 'on conflict do update set' query.

Working:

insert into statistics."MostPopularDependencies"
(id, indirect, downloads_week)
values ($1, $2, 1)
on conflict (id, indirect) do update
set downloads_week = statistics."MostPopularDependencies".downloads_week +
1
where statistics."MostPopularDependencies".id = $1 and
statistics."MostPopularDependencies".indirect = $2;

Not working:

insert into statistics."MostPopularDependencies"
(id, indirect, downloads_week)
values ($1, $2, 1)
on conflict
(id, indirect) -- also w/out this, it does not work too, but isn't it
optional element?
do update
set downloads_week = downloads_week + 1
where id = $1 and indirect = $2;

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

In reply to: Egor Pugin (#1)
Re: BUG #14327: UPSERT requires full path to column

On Mon, Sep 19, 2016 at 1:06 AM, <egor.pugin@gmail.com> wrote:

I've noticed upsert query won't work if I do not write 'schema.TABLE.column'
instead of simple 'column' in 'on conflict do update set' query.

Use an alias. e.g.:

INSERT INTO statistics."MostPopularDependencies" as mpd ...

You can then reference columns using mpd.downloads_week, etc

--
Peter Geoghegan

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#3Egor Pugin
egor.pugin@gmail.com
In reply to: Peter Geoghegan (#2)
Re: BUG #14327: UPSERT requires full path to column

Thanks!
But is this expected behavior and not a bug?

On 19 September 2016 at 13:06, Peter Geoghegan <pg@heroku.com> wrote:

On Mon, Sep 19, 2016 at 1:06 AM, <egor.pugin@gmail.com> wrote:

I've noticed upsert query won't work if I do not write 'schema.TABLE.column'
instead of simple 'column' in 'on conflict do update set' query.

Use an alias. e.g.:

INSERT INTO statistics."MostPopularDependencies" as mpd ...

You can then reference columns using mpd.downloads_week, etc

--
Peter Geoghegan

--
Egor Pugin

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs