+ href="#item4.11.1">4.11.1, it would look like this:
- You would then also have the new value stored in new_id
- for use in other queries (e.g., as a foreign key to the person
- table). Note that the name of the automatically created
- SEQUENCE object will be named <table>_<
- serialcolumn>_seq, where table and serialcolumn
- are the names of your table and your SERIAL column,
- respectively.
-
-
Alternatively, you could retrieve the assigned SERIAL
- value with the currval() function after it was inserted by
- default, e.g.,
- execute("INSERT INTO person (name) VALUES ('Blaise Pascal')");
- new_id = execute("SELECT currval('person_id_seq')");
+ INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id;
+ You can also call nextval() and use that value in the
+ INSERT, or call currval() after the
+ INSERT.
+
4.11.3) Doesn't currval()
lead to a race condition with other users?