Re: Data visibility

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Data visibility
Дата
Msg-id 24765.1160939750@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Data visibility  (Rafal Pietrak <rafal@zorro.isa-geek.com>)
Ответы Re: Data visibility  (Rafal Pietrak <rafal@zorro.isa-geek.com>)
Список pgsql-general
Rafal Pietrak <rafal@zorro.isa-geek.com> 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: Same-page UPDATEs in bloated tables
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Same-page UPDATEs in bloated tables