From: | "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com> |
---|---|
To: | "Jay O'Connor" <joconnor(at)cybermesa(dot)com> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Inserting a needed record before a select |
Date: | 2003-04-14 18:27:31 |
Message-ID: | Pine.LNX.4.33.0304141225520.18194-100000@css120.ihs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, 14 Apr 2003, Jay O'Connor wrote:
> 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
Crap, sorry, you're right. You'll need to use a rule. Rules are simpler
than triggers / functions. They're described in the programmer's guide,
section 13 for 7.3.2.
From | Date | Subject | |
---|---|---|---|
Next Message | Sean Chittenden | 2003-04-14 18:46:39 | Re: MySQL and RHDB news; 8.0 troll |
Previous Message | Andrew Sullivan | 2003-04-14 18:20:57 | Re: Batch replication ordering (was Re: [GENERAL] 32/64-bit |