Re: Using a rule as a trigger.

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Andrew Higgs <ahiggs(at)ps(dot)co(dot)za>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using a rule as a trigger.
Date: 2001-01-10 18:32:07
Message-ID: Pine.BSF.4.21.0101101031020.74211-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


As someone else said a serial is probably easier, but
a trigger is probably a better bet than a rule for this purpose.
Using a plpgsql before insert trigger will do it.

On Wed, 10 Jan 2001, Andrew Higgs wrote:

> Hi all,
>
> I have looked at some previous posting and thought that I had found
> exactly what I need. What I need is to insert an id (from a sequence)
> when a new record is inserted. The following example almost does what I
> need :
>
> CREATE TABLE topics (id int, topic varchar(50), descriotion text);
> CREATE SEQUENCE nextid start 1;
> CREATE RULE ins_topic AS ON INSERT TO topics WHERE id ISNULL DO UPDATE
> topics SET id=nextval('nextid') WHERE id ISNULL;
>
>
> This example updates the last insert. I need it to update the currnet
> insert. How do I do this?

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Markus Wagner 2001-01-10 18:39:27 connecting to postgres server from Access
Previous Message Stephan Szabo 2001-01-10 18:30:16 Re: Possible bug? WAS :Bad (null) varchar() external representation.