in sql server I do like this:
insert into foo(name) values('bob')
select @@identity;
so I get a query/scalar result displayed
how to this with postgres ?
Get a specific sequence:
SELECT currval('name_of_your_sequence');
Get the last value from the last sequence used:
SELECT lastval();
Check the manual as well: http://www.postgresql.org/docs/current/static/functions-sequence.html
Edit: You could also use RETURNING in your INSERT:
INSERT INTO foo(id, name) VALUES(DEFAULT, 'bob') RETURNING id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With