Received: from cr15.cristorei.com.br (cr15.cristorei.com.br [200.230.89.96]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f0AECvB29088 for ; Wed, 10 Jan 2001 09:12:57 -0500 (EST) (envelope-from mestredosmagos@marilia.com) Received: from marilia.com (escritorio.akacia.com.br [200.230.89.78]) by cr15.cristorei.com.br (8.9.3/8.8.7) with ESMTP id MAA04249; Wed, 10 Jan 2001 12:12:42 -0200 Message-ID: <3A5C709D.8438F2FE@marilia.com> Date: Wed, 10 Jan 2001 12:24:29 -0200 From: Tulio Oliveira Organization: Akacia Tecnologia X-Mailer: Mozilla 4.73 [pt_BR] (X11; U; Linux 2.2.14-19cl i686) X-Accept-Language: en MIME-Version: 1.0 To: Andrew Higgs CC: pgsql-sql@postgresql.org Subject: Re: Using a rule as a trigger. References: <3A5C2A94.8030408@ps.co.za> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200101/96 X-Sequence-Number: 757 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