pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: martin.nzioki@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #9006: Incorrect update when using where with non-existent column in subselect
Date: Tue, 28 Jan 2014 00:08:40 +0000
Message-ID: <20140128000840.26702.60938@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      9006
Logged by:          Martin Nzioki
Email address:      martin.nzioki@gmail.com
PostgreSQL version: 9.3.2
Operating system:   Windows 7 64-bit Professional SP1
Description:        

drop table if exists _test1;
drop table if exists _tmp_test2;

create table _test1 (id int not null primary key, c2 int);
insert into _test1 (id) select * from generate_series(1, 5);

create table _tmp_test2 (id_fk int not null);
insert into _tmp_test2 (id_fk) select id from _test1 limit 2;

update _test1 set c2 = 7 where id in (select id from _tmp_test2);
select * from _test1 order by id;

Expected results:
id,c2
--,--
1,7
2,7
3,
4,
5,

Actual results:
id,c2
--,--
1,7
2,7
3,7
4,7
5,7

Changing the update to

update _test1 set c2 = 7 where id in (select id_fk from _tmp_test2);

returns the expected results.

Expectation is that the non-existent id_fk would have been caught during
parsing.

This still happens even when each statement is executed in its own
transaction.

Using pgScript on pgAdmin:

[QUERY    ] drop table if exists _test1
            NOTICE:  table "_test1" does not exist, skipping
[QUERY    ] drop table if exists _tmp_test2
            NOTICE:  table "_tmp_test2" does not exist, skipping
[QUERY    ] create table _test1 (id int not null primary key, c2 int)
[QUERY    ] insert into _test1 (id) select * from generate_series(1, 5)
[QUERY    ] create table _tmp_test2 (id_fk int not null)
[QUERY    ] insert into _tmp_test2 (id_fk) select id from _test1 limit 2
[QUERY    ] update _test1 set c2 = 7 where id in (select id from
_tmp_test2)
[QUERY    ] select * from _test1 order by id



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



view thread (3+ messages)  latest in thread

Message-ID: <20140128000840.26702.60938@wrigleys.postgresql.org>
Permalink:  ../20140128000840.26702.60938@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20140128000840.26702.60938@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: martin.nzioki@gmail.com
  Subject: Re: BUG #9006: Incorrect update when using where with non-existent column in subselect
  In-Reply-To: <20140128000840.26702.60938@wrigleys.postgresql.org>
  References: <20140128000840.26702.60938@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox