> On Feb 14, 2017, at 2:55 PM, Patrick B <patrickbakerbr@gmail.com> wrote:
>
> 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
You want "select * from test ..." or "select id from test ..." here. Should work fine then.
>
> COMMIT;
>
> I only can see that inserted row if I do the select outside of this transaction.
>
> How could I get that ?
This'd be the idiomatic way of doing it:
INSERT INTO test (name,description) VALUES ('test 1','testing insert') RETURNING id;
Cheers,
Steve