Search Postgresql Archives

Re: Data visibility

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rafal Pietrak <rafal@xxxxxxxxxxxxxxxxxx> writes:
> CREATE TABLE master (id int not null unique, info text, ....);
> CREATE TABLE aux (master int references master(id), info text, ...);
> CREATE FUNCTION adjust() RETURNS "trigger" AS $$ BEGIN 
> 	new.id := 1000-old.id; 
> 	INSERT INTO aux (master, info) VALUES (new.id, 'hello world');
> 	RETURN new;
> END $$ LANGUAGE plpgsql;
> CREATE TRIGGER pico BEFORE INSERT ON master FOR EACH ROW EXECUTE
> PROCEDURE adjust();

> But in my trigger function "adjust()", executed within a transaction
> opened by "INSERT INTO master", the 'fresh' data (set by "new.id :=
> value") isn't visible to other commands (like: INSERT INTO aux...).

Well, of course not: it's a BEFORE trigger, so the row insertion hasn't
actually happened yet.  I think you need to split this operation into a
BEFORE trigger that changes the ID, and an AFTER trigger that propagates
the data into the other table.

			regards, tom lane


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux