Getting value of SERIAL column after insert from libpq?

From: "Mark Alliban" <MarkA(at)idnltd(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Getting value of SERIAL column after insert from libpq?
Date: 1999-12-20 14:18:15
Message-ID: 003401bf4af5$0f3b4a10$c80110ac@centauri
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have written a C program to insert a row into a table with a SERIAL column.

Is there a way of returning the inserted value for this column to my program? I.e. if there are rows with the serial column for 1,2,3,4 and 5, and I insert a row, my program needs to be told "6" for the new serial. There may be many instances of the program running simultaneously so I can't do a "select max..." or "select last_value..." workaround because by the time the select is done, there may have been other rows inserted so the last_value would be wrong. Also the program needs to be table-name and column-name independent so that it can work for ANY insert query into a table with a SERIAL column.

TIA,
Mark.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 1999-12-20 14:48:35 Re: [GENERAL] Getting value of SERIAL column after insert from libpq?
Previous Message Jose Soares 1999-12-20 13:51:23 Re: [GENERAL] copy command -- foiled by pg_atoi