Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B65C6B5DC3E for ; Wed, 21 Sep 2011 05:41:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 70935-08 for ; Wed, 21 Sep 2011 08:41:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail.csc.lt (mail.csc.lt [193.138.191.5]) by mail.postgresql.org (Postfix) with ESMTP id B5F6AB5DC3D for ; Wed, 21 Sep 2011 05:41:14 -0300 (ADT) Received: (qmail 10394 invoked by uid 210); 21 Sep 2011 08:41:13 -0000 Received: from mail.nsoft.lt by mail (envelope-from , uid 201) with qmail-scanner-2.05st (clamdscan: 0.97/13648. spamassassin: 3.2.1. perlscan: 2.05st. Clear:RC:1(77.240.249.53):. Processed in 0.019474 secs); 21 Sep 2011 08:41:13 -0000 Received: from mail.nsoft.lt (77.240.249.53) by mail.csc.lt with SMTP; 21 Sep 2011 08:41:13 -0000 Received: from [192.168.16.113] (unknown [77.240.249.53]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mail.nsoft.lt (Postfix) with ESMTPS id 85C648E1FC for ; Wed, 21 Sep 2011 11:41:10 +0300 (EEST) Message-ID: <4E79A327.5050902@nsoft.lt> Date: Wed, 21 Sep 2011 11:41:11 +0300 From: Julius Tuskenis Organization: UAB nSoft User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Re: currval() References: <93361C67E4EE844A80935863A4FF4B6C051150A2@Exch2010MB-2.univ.dir.wwu.edu> In-Reply-To: <93361C67E4EE844A80935863A4FF4B6C051150A2@Exch2010MB-2.univ.dir.wwu.edu> Content-Type: multipart/alternative; boundary="------------060006070001060900090309" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201109/145 X-Sequence-Number: 38382 This is a multi-part message in MIME format. --------------060006070001060900090309 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello, Mark On 2011.09.21 01:00, Marc Fromm wrote: > > The field name is ‘id’ and it is a primary key. > ... > > $sql .= "SELECT currval('id');"; > > > Marc > You should pass sequence name to currval (not field name like you do now). If you use pgAdmin sequence name is easily found looking at fields definition near the DEFAULT. example: ALTER TABLE b_preke ADD COLUMN prek_id integer; ALTER TABLE b_preke ALTER COLUMN prek_id SET NOT NULL; ALTER TABLE b_preke ALTER COLUMN prek_id SET DEFAULT nextval('b_preke_prek_id_seq'::regclass); the field is prek_id and the sequence is b_preke_prek_id_seq -- Julius Tuskenis Programavimo skyriaus vadovas UAB nSoft mob. +37068233050 --------------060006070001060900090309 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello, Mark

On 2011.09.21 01:00, Marc Fromm wrote:

The field name is ‘id’ and it is a primary key.

...

                $sql .= "SELECT currval('id');";


Marc

You should pass sequence name to currval (not field name like you do now). If you use pgAdmin sequence name is easily found looking at fields definition near the DEFAULT.

example:

ALTER TABLE b_preke ADD COLUMN prek_id integer;
ALTER TABLE b_preke ALTER COLUMN prek_id SET NOT NULL;
ALTER TABLE b_preke ALTER COLUMN prek_id SET DEFAULT nextval('b_preke_prek_id_seq'::regclass);

the field is prek_id and the sequence is b_preke_prek_id_seq
-- 
Julius Tuskenis
Programavimo skyriaus vadovas
UAB nSoft
mob. +37068233050
--------------060006070001060900090309--