1
1
2
2
Frequently Asked Questions (FAQ) for PostgreSQL
3
3
4
- Last updated: Sat Oct 13 01:26:55 EDT 2001
4
+ Last updated: Sun Oct 14 19:27:20 EDT 2001
5
5
6
6
Current maintainer: Bruce Momjian (
[email protected] )
7
7
@@ -826,10 +826,8 @@ BYTEA bytea variable-length byte array (null-safe)
826
826
object with the nextval() function before inserting and then insert it
827
827
explicitly. Using the example table in 4.16.1, that might look like
828
828
this in Perl:
829
- $sql = "SELECT nextval('person_id_seq')";
830
- $newSerialID = ($conn->selectrow_array($sql))[0];
831
- INSERT INTO person (id, name) VALUES ($newSerialID, 'Blaise Pascal');
832
- $res = $dbh->do($sql);
829
+ new_id = output of "SELECT nextval('person_id_seq')"
830
+ INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal');
833
831
834
832
You would then also have the new value stored in $newSerialID for use
835
833
in other queries (e.g., as a foreign key to the person table). Note
@@ -840,9 +838,7 @@ BYTEA bytea variable-length byte array (null-safe)
840
838
Alternatively, you could retrieve the assigned SERIAL value with the
841
839
currval() function after it was inserted by default, e.g.,
842
840
INSERT INTO person (name) VALUES ('Blaise Pascal');
843
- $res = $conn->do($sql);
844
- $sql = "SELECT currval('person_id_seq')";
845
- $newSerialID = ($conn->selectrow_array($sql))[0];
841
+ new_id = output of "SELECT currval('person_id_seq')";
846
842
847
843
Finally, you could use the OID returned from the INSERT statement to
848
844
look up the default value, though this is probably the least portable
0 commit comments