Unix Technical Forum

field-update in before-trigger causes distinct to 'fail', new in v8.1 versus v8.0.4, demo-sql included

This is a discussion on field-update in before-trigger causes distinct to 'fail', new in v8.1 versus v8.0.4, demo-sql included within the pgsql Bugs forums, part of the PostgreSQL category; --> L.S. I noticed that after creating these necessary objects: ================================================ create table t_src(value int); create table t_dest(value int primary ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 09:26 AM
Frank van Vugt
 
Posts: n/a
Default field-update in before-trigger causes distinct to 'fail', new in v8.1 versus v8.0.4, demo-sql included

L.S.

I noticed that after creating these necessary objects:

================================================
create table t_src(value int);
create table t_dest(value int primary key);
create or replace function tr_t_dest_before_iud()
returns trigger
language 'plpgsql'
volatile
strict
security invoker
AS ' declare
begin
RAISE NOTICE ''tr_t_dest_before_iud() triggered for value (%)'', NEW.value;
NEW.value = NEW.value + 1;
RETURN NEW;
END;';
create trigger t_dest_before before insert or update or delete on t_dest for
each row execute procedure tr_t_dest_before_iud();

insert into t_src values (1);
insert into t_src values (5);
insert into t_src values (9);
insert into t_src values (5);
================================================


The following statement causes an error due to the fact that the distinct
isn't producing distinct values anymore.

db=# insert into t_dest select distinct value from t_src;
NOTICE: tr_t_dest_before_iud() triggered for value (1)
NOTICE: tr_t_dest_before_iud() triggered for value (5)
NOTICE: tr_t_dest_before_iud() triggered for value (5)
ERROR: duplicate key violates unique constraint "t_dest_pkey"


This seems to be caused by the update of 'value' in the before-trigger.
Removing the update will let the distinct produce proper results.



4cleanup:
================================================
drop table t_dest;
drop table t_src;
drop function tr_t_dest_before_iud();
================================================


select version();
version
------------------------------------------------------------------------
PostgreSQL 8.1.0 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.3
(1 row)





--
Best,




Frank.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 09:27 AM
Tom Lane
 
Posts: n/a
Default Re: field-update in before-trigger causes distinct to 'fail', new in v8.1 versus v8.0.4, demo-sql included

Frank van Vugt <ftm.van.vugt@foxi.nl> writes:
> The following statement causes an error due to the fact that the distinct
> isn't producing distinct values anymore.
> This seems to be caused by the update of 'value' in the before-trigger.


Fix committed --- thanks for the report!

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 09:27 AM
Tom Lane
 
Posts: n/a
Default Re: field-update in before-trigger causes distinct to 'fail', new in v8.1 versus v8.0.4, demo-sql included

Frank van Vugt <ftm.van.vugt@foxi.nl> writes:
> (NB what would be the best way to get to such a patch without bothering you? I
> looked at the webcsv, but I wasn't sure whether you changed anything outside
> of execMain.c and execUtils.c and I'm not sure how to find out )


Looking at the pgsql-committers message is the easiest way to verify
which files were touched:
http://archives.postgresql.org/pgsql...1/msg00307.php
It also provides links that will give you the per-file diffs directly.

In this case, since the patch touches the widely known EState struct,
I'd recommend a full backend recompile after patching.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:36 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com