11
22 Frequently Asked Questions (FAQ) for PostgreSQL
33
4- Last updated: Sat Oct 13 01:26:55 EDT 2001
4+ Last updated: Sun Oct 14 19:27:20 EDT 2001
55
66 Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
77
@@ -826,10 +826,8 @@ BYTEA bytea variable-length byte array (null-safe)
826826 object with the nextval() function before inserting and then insert it
827827 explicitly. Using the example table in 4.16.1, that might look like
828828 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');
833831
834832 You would then also have the new value stored in $newSerialID for use
835833 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)
840838 Alternatively, you could retrieve the assigned SERIAL value with the
841839 currval() function after it was inserted by default, e.g.,
842840 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')";
846842
847843 Finally, you could use the OID returned from the INSERT statement to
848844 look up the default value, though this is probably the least portable
0 commit comments