Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.9.3/8.9.3) with ESMTP id MAA78652 for ; Sun, 12 Sep 1999 12:02:27 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id MAA02569; Sun, 12 Sep 1999 12:01:41 -0400 (EDT) To: theofilu@eunet.at cc: pgsql-interfaces@postgreSQL.org Subject: Re: [INTERFACES] ecpg and getting just assigned serial number In-reply-to: Your message of Sun, 12 Sep 1999 16:25:17 +0200 (MEST) <199909121425.QAA05055@eunet.at> Date: Sun, 12 Sep 1999 12:01:41 -0400 Message-ID: <2567.937152101@sss.pgh.pa.us> From: Tom Lane theofilu@eunet.at (Theofilu Andreas) writes: > to Informix's 'esqlc'. However. I have a table with a field of type > 'serial'. Now I've no problem to insert any sentences into this table, but > immediately after inserting a new sentence I need the newly assigned number > to the serial field in the table. How can I access this number? Postgres doesn't return that number automatically; you'll have to run a separate query to find out what was inserted. You could do something like select serialcolumn from table where oid = NNNN; since a single-row insert does return the OID of the inserted row. (Note this will be pretty slow if the table is big and does not have an index on OID.) Another possibility is to execute nextval() for yourself and then insert that result explicitly when you create the row. Still takes two queries, though. regards, tom lane