From: | "Jay O'Connor" <joconnor(at)cybermesa(dot)com> |
---|---|
To: | "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Inserting a needed record before a select |
Date: | 2003-04-14 18:04:21 |
Message-ID: | 3.0.1.32.20030414120421.00847e00@cybermesa.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Sullivan | 2003-04-14 18:08:39 | Re: Remote logging in postgres |
Previous Message | scott.marlowe | 2003-04-14 17:57:35 | Re: Inserting a needed record before a select |