Re: Inserting a needed record before a select - Mailing list pgsql-general

From Jay O'Connor
Subject Re: Inserting a needed record before a select
Date
Msg-id 3.0.1.32.20030414120421.00847e00@cybermesa.com
Whole thread Raw
In response to Re: Inserting a needed record before a select  ("scott.marlowe" <scott.marlowe@ihs.com>)
Responses Re: Inserting a needed record before a select  ("scott.marlowe" <scott.marlowe@ihs.com>)
List pgsql-general
At 11:57 AM 04/14/2003 -0600, scott.marlowe wrote:

>> What I need to do is to find a way to automallically insert a record if it
>> doesn'
>> t exist, prior to a SELECT.

>
>You're over halfway there.  Now you just need to do it in a trigger.
>Basically, in older versions of pgsql, you can change your
>function to return an opaque (in 7.3. it's now a trigger type, not sure
>about 7.2) and just check every time somebody selects from the table for
>the row and stick it in.  Then make a trigger on it.
>
>\h create trigger
>Command:     CREATE TRIGGER
>Description: define a new trigger
>Syntax:
>CREATE TRIGGER name { BEFORE | AFTER } { event [OR ...] }
>    ON table FOR EACH { ROW | STATEMENT }
>    EXECUTE PROCEDURE func ( arguments )
>
>So, after you've got a function that returns the right type,
>
>create trigger somename before select on tablename for each statement
>execute insertdefaultrow(rowid).


That's what I was thinking but the docs for CREATE TRIGGER say that the
event type can be either INSERT, UPDATE, or DELETE so I didn't think that a
trigger for before a select would work

Thanks


Take care,
Jay


pgsql-general by date:

Previous
From: Neil Conway
Date:
Subject: Re: Downloadable Version
Next
From: Andrew Sullivan
Date:
Subject: Re: Batch replication ordering (was Re: [GENERAL] 32/64-bit