X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4DA4BD1C50D for ; Fri, 15 Aug 2003 10:40:42 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 18731-09 for ; Fri, 15 Aug 2003 07:40:34 -0300 (ADT) Received: from zigo.dhs.org (as2-4-3.an.g.bonet.se [194.236.34.191]) by svr1.postgresql.org (Postfix) with ESMTP id 3ED3AD1C4B8 for ; Fri, 15 Aug 2003 07:40:30 -0300 (ADT) Received: from zigo.dhs.org (zigo [127.0.0.1]) by zigo.dhs.org (8.12.8/8.12.8) with ESMTP id h7FAeSMG010819; Fri, 15 Aug 2003 12:40:28 +0200 Received: from localhost (db@localhost) by zigo.dhs.org (8.12.8/8.12.8/Submit) with ESMTP id h7FAeS1G010815; Fri, 15 Aug 2003 12:40:28 +0200 Date: Fri, 15 Aug 2003 12:40:28 +0200 (CEST) From: =?ISO-8859-1?Q?Dennis_Bj=F6rklund?= To: cristi Cc: pgsql-sql@postgresql.org Subject: Re: sequence In-Reply-To: <006601c36310$29da3a20$7201a8c0@dmhi.ct.ro> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/190 X-Sequence-Number: 14806 On Fri, 15 Aug 2003, cristi wrote: > What is wrong here? > > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); Your probably want this instead: insert into table_name (field_name) values (nextval('sequence_name')); The reason why your insert fail above is that setval() should have more parameters, but even if it had worked it does not make sense to call setval() there. See http://www.postgresql.org/docs/7.3/static/functions-sequence.html Also, it's easier to use a serial column: http://www.postgresql.org/docs/7.3/static/datatype.html#DATATYPE-SERIAL then you can do insert into table_name (field_name) values (DEFAULT); -- /Dennis