Re: Using a rule as a trigger. - Mailing list pgsql-sql

From Tulio Oliveira
Subject Re: Using a rule as a trigger.
Date
Msg-id 3A5C709D.8438F2FE@marilia.com
Whole thread Raw
In response to Using a rule as a trigger.  (Andrew Higgs <ahiggs@ps.co.za>)
List pgsql-sql
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?
> 
> Kind regards
> Andrew Higgs



Isn't better create the field "id" as "serial" instead "int" ???

this will do what you need.

-- 
======================================================
AKACIA TECNOLOGIA
Desenvolvimento de sistemas para Internet
www.akacia.com.br


pgsql-sql by date:

Previous
From: Andrew Higgs
Date:
Subject: Using a rule as a trigger.
Next
From: Stephan Szabo
Date:
Subject: Re: Possible bug? WAS :Bad (null) varchar() external representation.