Received: from trends.net (root@clio.trends.ca [209.47.148.2]) by hub.org (8.9.3/8.9.3) with ESMTP id IAA01633 for ; Wed, 9 Jun 1999 08:09:04 -0400 (EDT) (envelope-from nuch@valigene.com) Received: from tom.oleane.net (tom.oleane.net [194.2.28.14]) by trends.net (8.8.8/8.8.8) with ESMTP id FAA23749 for ; Wed, 9 Jun 1999 05:43:32 -0400 (EDT) Received: from valigene.com ([62.161.254.162]) by tom.oleane.net (8.8.8/8.8.8) with ESMTP id LAA29623 for ; Wed, 9 Jun 1999 11:40:51 +0200 Sender: nuch@tom.oleane.net Message-ID: <375E2A1D.FC614366@valigene.com> Date: Wed, 09 Jun 1999 10:47:25 +0200 From: Nuchanard Chiannilkulchai Organization: ValiGene X-Mailer: Mozilla 4.07 [en] (X11; I; Linux 2.0.36 i686) MIME-Version: 1.0 To: pgsql-sql@hub.org Subject: automatic incrementation Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit hello, I have a table with the field 'id' which i would like to increment at each insert automatically. The idea is to create a function which determines the max(id) and then a rule to insert instead the real insertion instruction, with the next id value. -- table create table toto ( id int4 primary key, project char(8) not null, comments text ); insert into toto values (1,'PTest','ndfjSHJG'); insert into toto values (2,'PTest','ndfjSHJG'); insert into toto values (3,'PTest','ndfjSHJG'); -- function create function nextid(toto) returns int4 as ' select max($1.id)+1 as id ; ' language 'sql'; **** ERROR: type id lookup of 12 failed This is my first problem -- rule create rule r_id as on insert to toto do instead insert into toto (id, project, comments) values (nextid(), new.project, new.comments); **** The next problem may be the rule writing !!! I would like to have , even some other suggestions to make it works. I can't use a sequence table because I've already one in the database. Thanks, Nuch