Re: Emulating trigger BEFORE SELECT behavior - Mailing list pgsql-general

From Atri Sharma
Subject Re: Emulating trigger BEFORE SELECT behavior
Date
Msg-id CAOeZVidRs_dHbULZCvD5w-8iOedaHWZf5oTTLL5Mi-_afB1UTw@mail.gmail.com
Whole thread Raw
In response to Re: Emulating trigger BEFORE SELECT behavior  (Fabrízio de Royes Mello <fabriziomello@gmail.com>)
List pgsql-general
> Why you just create your track function and a view to call it?
>
> Example:
>
> BEGIN;
>
> CREATE TABLE foo (id SERIAL PRIMARY KEY, data TEXT);
> CREATE TABLE foo_track(tracktime TIMESTAMP DEFAULT now(), foo_row foo);
>
> INSERT INTO foo (data) SELECT 'Some Data'||id FROM generate_series(1,10) AS
> id;
>
> CREATE OR REPLACE FUNCTION foo_track_func(foo) RETURNS integer AS
> $$
>   INSERT INTO foo_track(foo_row) VALUES ($1) RETURNING (foo_row).id
> $$
> LANGUAGE sql;
>
> CREATE VIEW v_foo AS SELECT foo.*, foo_track_func(foo.*) FROM foo;
>
> SELECT * FROM v_foo;
> SELECT * FROM foo_track;
>
> COMMIT;
>
>

Wow! It seems just right. Thanks, let me try it out.

Regards,

Atri


--
Regards,

Atri
l'apprenant


pgsql-general by date:

Previous
From: Fabrízio de Royes Mello
Date:
Subject: Re: Emulating trigger BEFORE SELECT behavior
Next
From: "Sofer, Yuval"
Date:
Subject: Primary DB stuck becuase of unavailable standby (synchronized streaming) - please help