<H4><ANAME="4.16.2">4.16.2</A>) How do I get the back the generated SERIAL value after an insert?</H4><P>
Probably the simplest approach is to to retrieve the next SERIAL value from the sequence object with the <I>nextval()</I> function <I>before</I> inserting and then insert it explicitly. Using the example table in <AHREF="#4.16.1">4.16.1</A>, that might look like this:
<PRE>
$newSerialID = nextval('person_id_seq');
INSERT INTO person (id, name) VALUES ($newSerialID, 'Blaise Pascal');
</PRE>
You would then also have the new value stored in <CODE>$newSerialID</CODE> for use in other queries (e.g., as a foreign key to the <CODE>person</CODE> table). Note that the name of the automatically-created SEQUENCE object will be named <<I>table</I>>_<<I>serialcolumn</I>>_<I>seq</I>, where <I>table</I> and <I>serialcolumn</I> are the names of your table and your SERIAL column, respectively.
<P>
Similarly, you could retrieve the just-assigned SERIAL value with the <I>currval</I>() function <I>after</I> it was inserted by default, e.g.,
<PRE>
INSERT INTO person (name) VALUES ('Blaise Pascal');
$newID = currval('person_id_seq');
</PRE>
Finally, you could use the <AHREF="#4.17">oid</A> returned from the
INSERT statement to lookup the default value, though this is probably
the least portable approach. In perl, using DBI with Edmund Mergl's
DBD::Pg module, the oid value is made available via
$sth->{pg_oid_status} after $sth->execute().
<H4><ANAME="4.16.3">4.16.3</A>) Don't currval() and nextval() lead to a race condition with other
concurrent backend processes?</H4><P>
No. That has been handled by the backends.
<H4><ANAME="4.17">4.17</A>) What is an oid? What is a tid?</H4><P>
Oids are PostgreSQL's answer to unique row ids. Every row that is
created in PostgreSQL gets a unique oid. All oids generated during
initdb are less than 16384 (from <I>backend/access/transam.h</I>). All
user-created oids are equal or greater that this. By default, all these
oids are unique not only within a table, or database, but unique within
the entire PostgreSQL installation.<P>
PostgreSQL uses oids in its internal system tables to link rows between
tables. These oids can be used to identify specific user rows and used
in joins. It is recommended you use column type oid to store oid
values. See the <I>sql(l)</I> manual page to see the other internal columns.
You can create an index on the oid field for faster access.<P>
Oids are assigned to all new rows from a central area that is used by
all databases. If you want to change the oid to something else, or if
you want to make a copy of the table, with the original oid's, there is
no reason you can't do it:
<PRE>
CREATE TABLE new_table(old_oid oid, mycol int);
SELECT INTO new SELECT old_oid, mycol FROM old;
COPY new TO '/tmp/pgtable';
DELETE FROM new;
COPY new WITH OIDS FROM '/tmp/pgtable';
<!--
CREATE TABLE new_table (mycol int);
INSERT INTO new_table (oid, mycol) SELECT oid, mycol FROM old_table;
-->
</PRE><P>
Tids are used to identify specific physical rows with block and offset
values. Tids change after rows are modified or reloaded. They are used
by index entries to point to physical rows.<P>
<H4><ANAME="4.18">4.18</A>) What is the meaning of some of the terms
used in PostgreSQL?</H4><P>
Some of the source code and older documentation use terms that have more
common usage. Here are some:
<UL>
<LI> table, relation, class
<LI> row, record, tuple
<LI> column, field, attribute
<LI> retrieve, select
<LI> replace, update
<LI> append, insert
<LI> oid, serial value
<LI> portal, cursor
<LI> range variable, table name, table alias
</UL><P>
<H4><ANAME="4.19">4.19</A>) Why do I get the error "FATAL: palloc
failure: memory exhausted?"<BR></H4><P>
It is possible you have run out of virtual memory on your system, or
your kernel has a low limit for certain resources. Try this before
starting the postmaster:
<PRE>
ulimit -d 65536
limit datasize 64m
</PRE>
Depending on your shell, only one of these may succeed, but it will set
your process data segment limit much higher and perhaps allow the query
to complete. This command applies to the current process, and all
subprocesses created after the command is run. If you are having a problem
with the SQL client because the backend is returning too much data, try
it before starting the client.<P>
<H4><ANAME="4.20">4.20</A>) How do I tell what PostgreSQL version I
am running? <BR></H4><P>
From <I>psql,</I> type <CODE>select version();</CODE><P>
<H4><ANAME="4.21">4.21</A>) My large-object operations get <I>invalid
large obj descriptor.</I> Why? <BR></H4><P>
You need to put <CODE>BEGIN WORK</CODE> and <CODE>COMMIT
</CODE> around any use of a large object handle, that is,