[clug] OT: Postgresql serial primary keys

Alastair D'Silva alastair at d-silva.org
Tue Apr 5 11:53:31 UTC 2022

IIRC there is a last_insert_oid() function which will give you the oid of the row, which you can then use to get the pkey.

On 5 April 2022 3:51:32 pm AEST, Brett Worth via linux <linux at lists.samba.org> wrote:
>Hey all. I've googled my heart out but do not have an answer to my question.  I know there 
>are some knowledgeable people on this list so here goes:
>I have a database with two tables.  The first table has a column which is a "serial 
>primary key".
>While inside a transaction, I want to insert a row into the first table then use the 
>generated key as a value for inserts into the second table.
>If I select the max() value from the first table's key column, I cannot see the newly 
>generated value.  I suspect this is because I have not done a commit yet.
>Does anyone know if there's a magic way to see that value?
>I'm using postgresql 10.17.
>--  /) _ _ _/_/ / / /__ _ _//
>-- /_)/</= / / (_(_//_//< ///
>linux mailing list
>linux at lists.samba.org

Sent from my Android device with K-9 Mail. Please excuse my brevity.

More information about the linux mailing list