mirror of
https://github.com/postgres/postgres.git
synced 2025-06-05 23:56:58 +03:00
Update FAQ.
This commit is contained in:
parent
db7aa99fb9
commit
36458b93e0
15
doc/FAQ
15
doc/FAQ
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Frequently Asked Questions (FAQ) for PostgreSQL
|
Frequently Asked Questions (FAQ) for PostgreSQL
|
||||||
|
|
||||||
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)
|
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
|
||||||
|
|
||||||
@ -825,9 +825,11 @@ BYTEA bytea variable-length byte array (null-safe)
|
|||||||
One approach is to to retrieve the next SERIAL value from the sequence
|
One approach is to to retrieve the next SERIAL value from the sequence
|
||||||
object with the nextval() function before inserting and then insert it
|
object with the nextval() function before inserting and then insert it
|
||||||
explicitly. Using the example table in 4.16.1, that might look like
|
explicitly. Using the example table in 4.16.1, that might look like
|
||||||
this:
|
this in Perl:
|
||||||
$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');
|
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
|
You would then also have the new value stored in $newSerialID for use
|
||||||
in other queries (e.g., as a foreign key to the person table). Note
|
in other queries (e.g., as a foreign key to the person table). Note
|
||||||
@ -838,7 +840,9 @@ BYTEA bytea variable-length byte array (null-safe)
|
|||||||
Alternatively, you could retrieve the assigned SERIAL value with the
|
Alternatively, you could retrieve the assigned SERIAL value with the
|
||||||
currval() function after it was inserted by default, e.g.,
|
currval() function after it was inserted by default, e.g.,
|
||||||
INSERT INTO person (name) VALUES ('Blaise Pascal');
|
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
|
Finally, you could use the OID returned from the INSERT statement to
|
||||||
look up the default value, though this is probably the least portable
|
look up the default value, though this is probably the least portable
|
||||||
@ -849,7 +853,8 @@ BYTEA bytea variable-length byte array (null-safe)
|
|||||||
4.16.3) Don't currval() and nextval() lead to a race condition with other
|
4.16.3) Don't currval() and nextval() lead to a race condition with other
|
||||||
users?
|
users?
|
||||||
|
|
||||||
No. This is handled by the backends.
|
No. Currval() returns the current value assigned by your backend, not
|
||||||
|
by all users.
|
||||||
|
|
||||||
4.17) What is an OID? What is a TID?
|
4.17) What is an OID? What is a TID?
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
alink="#0000FF">
|
alink="#0000FF">
|
||||||
<H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
|
<H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
|
||||||
|
|
||||||
<P>Last updated: Fri Oct 12 23:37:30 EDT 2001</P>
|
<P>Last updated: Fri Oct 12 23:53:35 EDT 2001</P>
|
||||||
|
|
||||||
<P>Current maintainer: Bruce Momjian (<A href=
|
<P>Current maintainer: Bruce Momjian (<A href=
|
||||||
"mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
|
"mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
|
||||||
@ -1046,10 +1046,12 @@ BYTEA bytea variable-length byte array (null-safe)
|
|||||||
value from the sequence object with the <I>nextval()</I> function
|
value from the sequence object with the <I>nextval()</I> function
|
||||||
<I>before</I> inserting and then insert it explicitly. Using the
|
<I>before</I> inserting and then insert it explicitly. Using the
|
||||||
example table in <A href="#4.16.1">4.16.1</A>, that might look like
|
example table in <A href="#4.16.1">4.16.1</A>, that might look like
|
||||||
this:</P>
|
this in Perl:</P>
|
||||||
<PRE>
|
<PRE>
|
||||||
$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');
|
INSERT INTO person (id, name) VALUES ($newSerialID, 'Blaise Pascal');
|
||||||
|
$res = $dbh->do($sql);
|
||||||
</PRE>
|
</PRE>
|
||||||
You would then also have the new value stored in
|
You would then also have the new value stored in
|
||||||
<CODE>$newSerialID</CODE> for use in other queries (e.g., as a
|
<CODE>$newSerialID</CODE> for use in other queries (e.g., as a
|
||||||
@ -1064,7 +1066,9 @@ BYTEA bytea variable-length byte array (null-safe)
|
|||||||
<I>after</I> it was inserted by default, e.g.,</P>
|
<I>after</I> it was inserted by default, e.g.,</P>
|
||||||
<PRE>
|
<PRE>
|
||||||
INSERT INTO person (name) VALUES ('Blaise Pascal');
|
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];
|
||||||
</PRE>
|
</PRE>
|
||||||
Finally, you could use the <A href="#4.17"><SMALL>OID</SMALL></A>
|
Finally, you could use the <A href="#4.17"><SMALL>OID</SMALL></A>
|
||||||
returned from the <SMALL>INSERT</SMALL> statement to look up the
|
returned from the <SMALL>INSERT</SMALL> statement to look up the
|
||||||
@ -1076,7 +1080,8 @@ BYTEA bytea variable-length byte array (null-safe)
|
|||||||
<H4><A name="4.16.3">4.16.3</A>) Don't <I>currval()</I> and
|
<H4><A name="4.16.3">4.16.3</A>) Don't <I>currval()</I> and
|
||||||
<I>nextval()</I> lead to a race condition with other users?</H4>
|
<I>nextval()</I> lead to a race condition with other users?</H4>
|
||||||
|
|
||||||
<P>No. This is handled by the backends.</P>
|
<P>No. Currval() returns the current value assigned by your
|
||||||
|
backend, not by all users.</P>
|
||||||
|
|
||||||
<H4><A name="4.17">4.17</A>) What is an <SMALL>OID</SMALL>? What is
|
<H4><A name="4.17">4.17</A>) What is an <SMALL>OID</SMALL>? What is
|
||||||
a <SMALL>TID</SMALL>?</H4>
|
a <SMALL>TID</SMALL>?</H4>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user