From 36458b93e0961c983f76db415aa0aeef9ebeeffd Mon Sep 17 00:00:00 2001
From: Bruce Momjian Last updated: Fri Oct 12 23:37:30 EDT 2001 Last updated: Fri Oct 12 23:53:35 EDT 2001 Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)Frequently Asked Questions (FAQ) for PostgreSQL
-
@@ -1046,10 +1046,12 @@ BYTEA bytea variable-length byte array (null-safe)
value from the sequence object with the nextval() function
before inserting and then insert it explicitly. Using the
example table in 4.16.1, that might look like
- this:
- $newSerialID = nextval('person_id_seq'); + $sql = "SELECT nextval('person_id_seq')"; + $newSerialID = ($conn->selectrow_array($sql))[0]; INSERT INTO person (id, name) VALUES ($newSerialID, 'Blaise Pascal'); + $res = $dbh->do($sql);You would then also have the new value stored in
$newSerialID
for use in other queries (e.g., as a
@@ -1064,7 +1066,9 @@ BYTEA bytea variable-length byte array (null-safe)
after it was inserted by default, e.g.,
INSERT INTO person (name) VALUES ('Blaise Pascal'); - $newID = currval('person_id_seq'); + $res = $conn->do($sql); + $sql = "SELECT currval('person_id_seq')"; + $newSerialID = ($conn->selectrow_array($sql))[0];Finally, you could use the OID returned from the INSERT statement to look up the @@ -1076,7 +1080,8 @@ BYTEA bytea variable-length byte array (null-safe)
No. This is handled by the backends.
+No. Currval() returns the current value assigned by your + backend, not by all users.