pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14209: Rules don't validate duplicated keys
2+ messages / 2 participants
[nested] [flat]
* BUG #14209: Rules don't validate duplicated keys
@ 2016-06-22 22:40 juniorperezpy@gmail.com
0 siblings, 1 reply; 2+ messages in thread
From: juniorperezpy@gmail.com @ 2016-06-22 22:40 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14209
Logged by: Abdel Perez
Email address: juniorperezpy@gmail.com
PostgreSQL version: 9.5.1
Operating system: Window 7 Professional
Description:
I've a list with duplicates values I use like pk and I create a rule like
this:
CREATE OR REPLACE RULE db_table_ignore_duplicate_inserts AS
ON INSERT TO products
WHERE (EXISTS ( SELECT 1
FROM products
WHERE products.id = new.id AND btrim(products.description::text) =
btrim(new.description::text))) DO INSTEAD NOTHING;
when I insert individually the rule works and its says me he ignores the
duplicate row, but when insert this way:
insert into products (id, description) values (1, 'product1'), (1,
'producto1);
he inserts anyway the two rows.
I didn't see in the documentation that the rule must ignore this cases.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #14209: Rules don't validate duplicated keys
@ 2016-06-22 23:58 David G. Johnston <david.g.johnston@gmail.com>
parent: juniorperezpy@gmail.com
0 siblings, 0 replies; 2+ messages in thread
From: David G. Johnston @ 2016-06-22 23:58 UTC (permalink / raw)
To: juniorperezpy@gmail.com; +Cc: pgsql-bugs
On Wed, Jun 22, 2016 at 6:40 PM, <juniorperezpy@gmail.com> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 14209
> Logged by: Abdel Perez
> Email address: juniorperezpy@gmail.com
> PostgreSQL version: 9.5.1
> Operating system: Window 7 Professional
> Description:
>
> I've a list with duplicates values I use like pk and I create a rule like
> this:
>
> CREATE OR REPLACE RULE db_table_ignore_duplicate_inserts AS
> ON INSERT TO products
> WHERE (EXISTS ( SELECT 1
> FROM products
> WHERE products.id = new.id AND
> btrim(products.description::text) =
> btrim(new.description::text))) DO INSTEAD NOTHING;
>
> when I insert individually the rule works and its says me he ignores the
> duplicate row, but when insert this way:
>
> insert into products (id, description) values (1, 'product1'), (1,
> 'producto1);
>
> he inserts anyway the two rows.
>
> I didn't see in the documentation that the rule must ignore this cases.
>
>
Maybe someone more knowledgeable will jump in with specifics (or propose a
-doc patch with them incorporated) since its not self-evident how a
multi-value insert resolves in this setup. Not that rules get much lovin'
now-a-days; you should consider (even if this did work) alternatives.
Before the rule is evaluated there are zero records with id=1; Only after
the rule (and any other) is fully resolved are any of the output query
trees executed. Thus the WHERE EXISTS does not evaluate any data that has
been inserted via the query it is rewriting. Therefore DO INSTEAD NOTHING
either applies to both records (if id=1 exists previously) or neither.
Whether the generated query tree is a single tree that gets fed two rows
during execution, or a pair of trees each being fed a single row during
execution, I do not know and could not discover from a quick scan of the
documentation. Either way a violation of the UNIQUE constraint on the id
column is going to happen.
David J.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2016-06-22 23:58 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-06-22 22:40 BUG #14209: Rules don't validate duplicated keys juniorperezpy@gmail.com
2016-06-22 23:58 ` David G. Johnston <david.g.johnston@gmail.com>
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