get inserted id from transaction - PG 9.2

From: Patrick B <patrickbakerbr(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: get inserted id from transaction - PG 9.2
Date: 2017-02-14 22:55:05
Message-ID: CAJNY3ivakPDmoNZGmsBeGpK-Y_hWZzQRK9FRMacDS7pGGoz0yw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I'm simply doing an insert and I want to get the inserted id with a select.
I'm doing this all in the same transactions.

Example:

BEGIN;

INSERT INTO test (id,name,description) VALUES (default,'test 1','testing
insert');

SELECT FROM test ORDER BY id DESC; -- I don't see the inserted row here

COMMIT;

I only can see that inserted row if I do the select outside of this
transaction.

How could I get that ?

Thanks!
Patrick

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2017-02-14 23:11:46 Re: get inserted id from transaction - PG 9.2
Previous Message Tom Lane 2017-02-14 21:38:50 Re: Bad planning data resulting in OOM killing of postgres