"Kevin B." <db@ke5in.com> writes:
> I see that you can create an implicit sequence like this:
> CREATE TABLE test (field varchar(5), id serial NOT NULL, PRIMARY KEY (id));
Right.
> And I've read that you can replace the Microsoft @@Identity by using this:
> select last_value from test_id_seq;
No. You want
SELECT currval('test_id_seq');
> But what if somebody else inserts a row after your insert but before your
> select?
currval is session-local so it's not affected by what other people do.
This is why you want to look at it and not at last_value. (I think
there are some cache effects that also make last_value less than useful,
but the concurrency reason is sufficient...)
regards, tom lane