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 5DC9BD1B539 for ; Fri, 15 Aug 2003 12:02:25 +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 36548-08 for ; Fri, 15 Aug 2003 09:02:17 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 483BAD1C4D6 for ; Fri, 15 Aug 2003 09:02:14 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h7FC1k5H012593; Fri, 15 Aug 2003 08:01:46 -0400 (EDT) To: "cristi" Cc: pgsql-sql@postgresql.org Subject: Re: sequence In-reply-to: <006601c36310$29da3a20$7201a8c0@dmhi.ct.ro> References: <006601c36310$29da3a20$7201a8c0@dmhi.ct.ro> Comments: In-reply-to "cristi" message dated "Fri, 15 Aug 2003 12:32:36 +0300" Date: Fri, 15 Aug 2003 08:01:46 -0400 Message-ID: <12592.1060948906@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/192 X-Sequence-Number: 14808 "cristi" writes: > What is wrong here? > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); Either too few parentheses, or too many ;-) You could write this as an INSERT/SELECT: insert into table_name (field_name) select setval('sequence_name')-1 as currval; or you could write it as an INSERT/VALUES with scalar subquery expression: insert into table_name (field_name) values ((select setval('sequence_name')-1 as currval)); (all the parentheses are required here). But really you do not need a subquery for this at all; VALUES is perfectly content with scalar expressions: insert into table_name (field_name) values (setval('sequence_name')-1); regards, tom lane