Commit 0b79ed27 authored by Bruce Momjian's avatar Bruce Momjian

Update FAQ.

parent b5213b5c
Frequently Asked Questions (FAQ) for PostgreSQL Frequently Asked Questions (FAQ) for PostgreSQL
Last updated: Wed Dec 5 00:41:12 EST 2001 Last updated: Fri Jan 4 00:44:42 EST 2002
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us) Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
...@@ -58,42 +58,39 @@ ...@@ -58,42 +58,39 @@
Operational Questions Operational Questions
4.1) Why is the system confused about commas, decimal points, and date 4.1) What is the difference between binary cursors and normal cursors?
formats. 4.2) How do I SELECT only the first few rows of a query?
4.2) What is the exact difference between binary cursors and normal 4.3) How do I get a list of tables or other things I can see in psql?
cursors? 4.4) How do you remove a column from a table?
4.3) How do I SELECT only the first few rows of a query? 4.5) What is the maximum size for a row, table, database?
4.4) How do I get a list of tables or other things I can see in psql? 4.6) How much database disk space is required to store data from a
4.5) How do you remove a column from a table?
4.6) What is the maximum size for a row, table, database?
4.7) How much database disk space is required to store data from a
typical text file? typical text file?
4.8) How do I find out what tables or indexes are defined in the 4.7) How do I find out what tables or indexes are defined in the
database? database?
4.9) My queries are slow or don't make use of the indexes. Why? 4.8) My queries are slow or don't make use of the indexes. Why?
4.10) How do I see how the query optimizer is evaluating my query? 4.9) How do I see how the query optimizer is evaluating my query?
4.11) What is an R-tree index? 4.10) What is an R-tree index?
4.12) What is the Genetic Query Optimizer? 4.11) What is the Genetic Query Optimizer?
4.13) How do I perform regular expression searches and 4.12) How do I perform regular expression searches and
case-insensitive regular expression searches? How do I use an index case-insensitive regular expression searches? How do I use an index
for case-insensitive searches? for case-insensitive searches?
4.14) In a query, how do I detect if a field is NULL? 4.13) In a query, how do I detect if a field is NULL?
4.15) What is the difference between the various character types? 4.14) What is the difference between the various character types?
4.16.1) How do I create a serial/auto-incrementing field? 4.15.1) How do I create a serial/auto-incrementing field?
4.16.2) How do I get the value of a SERIAL insert? 4.15.2) How do I get the value of a SERIAL insert?
4.16.3) Don't currval() and nextval() lead to a race condition with 4.15.3) Don't currval() and nextval() lead to a race condition with
other users? other users?
4.17) What is an OID? What is a TID? 4.16) What is an OID? What is a TID?
4.18) What is the meaning of some of the terms used in PostgreSQL? 4.17) What is the meaning of some of the terms used in PostgreSQL?
4.19) Why do I get the error "ERROR: Memory exhausted in 4.18) Why do I get the error "ERROR: Memory exhausted in
AllocSetAlloc()?" AllocSetAlloc()?"
4.20) How do I tell what PostgreSQL version I am running? 4.19) How do I tell what PostgreSQL version I am running?
4.21) My large-object operations get invalid large obj descriptor. 4.20) My large-object operations get invalid large obj descriptor.
Why? Why?
4.22) How do I create a column that will default to the current time? 4.21) How do I create a column that will default to the current time?
4.23) Why are my subqueries using IN so slow? 4.22) Why are my subqueries using IN so slow?
4.24) How do I perform an outer join? 4.23) How do I perform an outer join?
4.25) How do I perform queries using multiple databases? 4.24) How do I perform queries using multiple databases?
Extending PostgreSQL Extending PostgreSQL
...@@ -611,19 +608,11 @@ ...@@ -611,19 +608,11 @@
Operational Questions Operational Questions
4.1) Why is system confused about commas, decimal points, and date formats. 4.1) What is the difference between binary cursors and normal cursors?
Check your locale configuration. PostgreSQL uses the locale setting of
the user that ran the postmaster process. There are postgres and psql
SET commands to control the date format. Set those accordingly for
your operating environment.
4.2) What is the exact difference between binary cursors and normal
cursors?
See the DECLARE manual page for a description. See the DECLARE manual page for a description.
4.3) How do I SELECT only the first few rows of a query? 4.2) How do I SELECT only the first few rows of a query?
See the FETCH manual page, or use SELECT ... LIMIT.... See the FETCH manual page, or use SELECT ... LIMIT....
...@@ -633,7 +622,7 @@ ...@@ -633,7 +622,7 @@
only the first few records requested, or the entire query may have to only the first few records requested, or the entire query may have to
be evaluated until the desired rows have been generated. be evaluated until the desired rows have been generated.
4.4) How do I get a list of tables or other things I can see in psql? 4.3) How do I get a list of tables or other things I can see in psql?
You can read the source code for psql in file You can read the source code for psql in file
pgsql/src/bin/psql/describe.c. It contains SQL commands that generate pgsql/src/bin/psql/describe.c. It contains SQL commands that generate
...@@ -641,7 +630,7 @@ ...@@ -641,7 +630,7 @@
the -E option so it will print out the queries it uses to execute the the -E option so it will print out the queries it uses to execute the
commands you give. commands you give.
4.5) How do you remove a column from a table? 4.4) How do you remove a column from a table?
We do not support ALTER TABLE DROP COLUMN, but do this: We do not support ALTER TABLE DROP COLUMN, but do this:
SELECT ... -- select all columns but the one you want to remove SELECT ... -- select all columns but the one you want to remove
...@@ -650,7 +639,7 @@ ...@@ -650,7 +639,7 @@
DROP TABLE old_table; DROP TABLE old_table;
ALTER TABLE new_table RENAME TO old_table; ALTER TABLE new_table RENAME TO old_table;
4.6) What is the maximum size for a row, table, database? 4.5) What is the maximum size for a row, table, database?
These are the limits: These are the limits:
Maximum size for a database? unlimited (60GB databases exist) Maximum size for a database? unlimited (60GB databases exist)
...@@ -672,7 +661,7 @@ ...@@ -672,7 +661,7 @@
The maximum table size and maximum number of columns can be increased The maximum table size and maximum number of columns can be increased
if the default block size is increased to 32k. if the default block size is increased to 32k.
4.7) How much database disk space is required to store data from a typical 4.6) How much database disk space is required to store data from a typical
text file? text file?
A PostgreSQL database may need six-and-a-half times the disk space A PostgreSQL database may need six-and-a-half times the disk space
...@@ -702,7 +691,7 @@ ...@@ -702,7 +691,7 @@
Indexes do not require as much overhead, but do contain the data that Indexes do not require as much overhead, but do contain the data that
is being indexed, so they can be large also. is being indexed, so they can be large also.
4.8) How do I find out what tables or indexes are defined in the database? 4.7) How do I find out what tables or indexes are defined in the database?
psql has a variety of backslash commands to show such information. Use psql has a variety of backslash commands to show such information. Use
\? to see them. \? to see them.
...@@ -711,7 +700,7 @@ ...@@ -711,7 +700,7 @@
many of the SELECTs needed to get information from the database system many of the SELECTs needed to get information from the database system
tables. tables.
4.9) My queries are slow or don't make use of the indexes. Why? 4.8) My queries are slow or don't make use of the indexes. Why?
PostgreSQL does not automatically maintain statistics. VACUUM must be PostgreSQL does not automatically maintain statistics. VACUUM must be
run to update the statistics. After statistics are updated, the run to update the statistics. After statistics are updated, the
...@@ -736,11 +725,11 @@ ...@@ -736,11 +725,11 @@
string. So, to use indices, LIKE searches should not begin with %, and string. So, to use indices, LIKE searches should not begin with %, and
~(regular expression searches) should start with ^. ~(regular expression searches) should start with ^.
4.10) How do I see how the query optimizer is evaluating my query? 4.9) How do I see how the query optimizer is evaluating my query?
See the EXPLAIN manual page. See the EXPLAIN manual page.
4.11) What is an R-tree index? 4.10) What is an R-tree index?
An R-tree index is used for indexing spatial data. A hash index can't An R-tree index is used for indexing spatial data. A hash index can't
handle range searches. A B-tree index only handles range searches in a handle range searches. A B-tree index only handles range searches in a
...@@ -763,13 +752,13 @@ ...@@ -763,13 +752,13 @@
extending R-trees requires a bit of work and we don't currently have extending R-trees requires a bit of work and we don't currently have
any documentation on how to do it. any documentation on how to do it.
4.12) What is the Genetic Query Optimizer? 4.11) What is the Genetic Query Optimizer?
The GEQO module speeds query optimization when joining many tables by The GEQO module speeds query optimization when joining many tables by
means of a Genetic Algorithm (GA). It allows the handling of large means of a Genetic Algorithm (GA). It allows the handling of large
join queries through nonexhaustive search. join queries through nonexhaustive search.
4.13) How do I perform regular expression searches and case-insensitive 4.12) How do I perform regular expression searches and case-insensitive
regular expression searches? How do I use an index for case-insensitive regular expression searches? How do I use an index for case-insensitive
searches? searches?
...@@ -788,11 +777,11 @@ ...@@ -788,11 +777,11 @@
CREATE INDEX tabindex on tab (lower(col)); CREATE INDEX tabindex on tab (lower(col));
4.14) In a query, how do I detect if a field is NULL? 4.13) In a query, how do I detect if a field is NULL?
You test the column with IS NULLIS NOT NULL. You test the column with IS NULLIS NOT NULL.
4.15) What is the difference between the various character types? 4.14) What is the difference between the various character types?
Type Internal Name Notes Type Internal Name Notes
-------------------------------------------------- --------------------------------------------------
...@@ -817,7 +806,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -817,7 +806,7 @@ BYTEA bytea variable-length byte array (null-safe)
maximum 1 gigabyte. BYTEA is for storing binary data, particularly maximum 1 gigabyte. BYTEA is for storing binary data, particularly
values that include NULL bytes. values that include NULL bytes.
4.16.1) How do I create a serial/auto-incrementing field? 4.15.1) How do I create a serial/auto-incrementing field?
PostgreSQL supports a SERIAL data type. It auto-creates a sequence and PostgreSQL supports a SERIAL data type. It auto-creates a sequence and
index on the column. For example, this: index on the column. For example, this:
...@@ -841,11 +830,11 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -841,11 +830,11 @@ BYTEA bytea variable-length byte array (null-safe)
Numbering Rows. Numbering Rows.
4.16.2) How do I get the value of a SERIAL insert? 4.15.2) How do I get the value of a SERIAL insert?
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.15.1, that might look like
this in Perl: this in Perl:
new_id = output of "SELECT nextval('person_id_seq')" new_id = output of "SELECT nextval('person_id_seq')"
INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal'); INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal');
...@@ -867,13 +856,13 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -867,13 +856,13 @@ BYTEA bytea variable-length byte array (null-safe)
oid value is made available via $sth->{pg_oid_status} after oid value is made available via $sth->{pg_oid_status} after
$sth->execute(). $sth->execute().
4.16.3) Don't currval() and nextval() lead to a race condition with other 4.15.3) Don't currval() and nextval() lead to a race condition with other
users? users?
No. Currval() returns the current value assigned by your backend, not No. Currval() returns the current value assigned by your backend, not
by all users. by all users.
4.17) What is an OID? What is a TID? 4.16) What is an OID? What is a TID?
OIDs are PostgreSQL's answer to unique row ids. Every row that is OIDs are PostgreSQL's answer to unique row ids. Every row that is
created in PostgreSQL gets a unique OID. All OIDs generated during created in PostgreSQL gets a unique OID. All OIDs generated during
...@@ -906,7 +895,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -906,7 +895,7 @@ BYTEA bytea variable-length byte array (null-safe)
values. Tids change after rows are modified or reloaded. They are used values. Tids change after rows are modified or reloaded. They are used
by index entries to point to physical rows. by index entries to point to physical rows.
4.18) What is the meaning of some of the terms used in PostgreSQL? 4.17) What is the meaning of some of the terms used in PostgreSQL?
Some of the source code and older documentation use terms that have Some of the source code and older documentation use terms that have
more common usage. Here are some: more common usage. Here are some:
...@@ -923,7 +912,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -923,7 +912,7 @@ BYTEA bytea variable-length byte array (null-safe)
A list of general database terms can be found at: A list of general database terms can be found at:
http://www.comptechnews.com/~reaster/dbdesign.html http://www.comptechnews.com/~reaster/dbdesign.html
4.19) Why do I get the error "ERROR: Memory exhausted in AllocSetAlloc()?" 4.18) Why do I get the error "ERROR: Memory exhausted in AllocSetAlloc()?"
If you are running a version older than 7.1, an upgrade may fix the If you are running a version older than 7.1, an upgrade may fix the
problem. Also it is possible you have run out of virtual memory on problem. Also it is possible you have run out of virtual memory on
...@@ -939,11 +928,11 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -939,11 +928,11 @@ BYTEA bytea variable-length byte array (null-safe)
problem with the SQL client because the backend is returning too much problem with the SQL client because the backend is returning too much
data, try it before starting the client. data, try it before starting the client.
4.20) How do I tell what PostgreSQL version I am running? 4.19) How do I tell what PostgreSQL version I am running?
From psql, type select version(); From psql, type select version();
4.21) My large-object operations get invalid large obj descriptor. Why? 4.20) My large-object operations get invalid large obj descriptor. Why?
You need to put BEGIN WORK and COMMIT around any use of a large object You need to put BEGIN WORK and COMMIT around any use of a large object
handle, that is, surrounding lo_open ... lo_close. handle, that is, surrounding lo_open ... lo_close.
...@@ -957,12 +946,12 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -957,12 +946,12 @@ BYTEA bytea variable-length byte array (null-safe)
If you are using a client interface like ODBC you may need to set If you are using a client interface like ODBC you may need to set
auto-commit off. auto-commit off.
4.22) How do I create a column that will default to the current time? 4.21) How do I create a column that will default to the current time?
Use CURRENT_TIMESTAMP: Use CURRENT_TIMESTAMP:
CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
4.23) Why are my subqueries using IN so slow? 4.22) Why are my subqueries using IN so slow?
Currently, we join subqueries to outer queries by sequentially Currently, we join subqueries to outer queries by sequentially
scanning the result of the subquery for each row of the outer query. A scanning the result of the subquery for each row of the outer query. A
...@@ -978,7 +967,7 @@ SELECT * ...@@ -978,7 +967,7 @@ SELECT *
We hope to fix this limitation in a future release. We hope to fix this limitation in a future release.
4.24) How do I perform an outer join? 4.23) How do I perform an outer join?
PostgreSQL 7.1 and later supports outer joins using the SQL standard PostgreSQL 7.1 and later supports outer joins using the SQL standard
syntax. Here are two examples: syntax. Here are two examples:
...@@ -1008,7 +997,7 @@ SELECT * ...@@ -1008,7 +997,7 @@ SELECT *
WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2) WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2)
ORDER BY col1 ORDER BY col1
4.25) How do I perform queries using multiple databases? 4.24) How do I perform queries using multiple databases?
There is no way to query any database except the current one. Because There is no way to query any database except the current one. Because
PostgreSQL loads database-specific system catalogs, it is uncertain PostgreSQL loads database-specific system catalogs, it is uncertain
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
alink="#0000FF"> alink="#0000FF">
<H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1> <H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
<P>Last updated: Wed Dec 5 00:41:12 EST 2001</P> <P>Last updated: Fri Jan 4 00:44:42 EST 2002</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>
...@@ -89,57 +89,55 @@ ...@@ -89,57 +89,55 @@
<CENTER> <CENTER>
<H2>Operational Questions</H2> <H2>Operational Questions</H2>
</CENTER> </CENTER>
<A href="#4.1">4.1</A>) Why is the system confused about commas, <A href="#4.1">4.1</A>) What is the difference between
decimal points, and date formats.<BR>
<A href="#4.2">4.2</A>) What is the exact difference between
binary cursors and normal cursors?<BR> binary cursors and normal cursors?<BR>
<A href="#4.3">4.3</A>) How do I <SMALL>SELECT</SMALL> only the <A href="#4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
first few rows of a query?<BR> first few rows of a query?<BR>
<A href="#4.4">4.4</A>) How do I get a list of tables or other <A href="#4.3">4.3</A>) How do I get a list of tables or other
things I can see in <I>psql?</I><BR> things I can see in <I>psql?</I><BR>
<A href="#4.5">4.5</A>) How do you remove a column from a <A href="#4.4">4.4</A>) How do you remove a column from a
table?<BR> table?<BR>
<A href="#4.6">4.6</A>) What is the maximum size for a row, table, <A href="#4.5">4.5</A>) What is the maximum size for a row, table,
database?<BR> database?<BR>
<A href="#4.7">4.7</A>) How much database disk space is required <A href="#4.6">4.6</A>) How much database disk space is required
to store data from a typical text file?<BR> to store data from a typical text file?<BR>
<A href="#4.8">4.8</A>) How do I find out what tables or indexes <A href="#4.7">4.7</A>) How do I find out what tables or indexes
are defined in the database?<BR> are defined in the database?<BR>
<A href="#4.9">4.9</A>) My queries are slow or don't make use of <A href="#4.8">4.8</A>) My queries are slow or don't make use of
the indexes. Why?<BR> the indexes. Why?<BR>
<A href="#4.10">4.10</A>) How do I see how the query optimizer is <A href="#4.9">4.9</A>) How do I see how the query optimizer is
evaluating my query?<BR> evaluating my query?<BR>
<A href="#4.11">4.11</A>) What is an R-tree index?<BR> <A href="#4.10">4.10</A>) What is an R-tree index?<BR>
<A href="#4.12">4.12</A>) What is the Genetic Query Optimizer?<BR> <A href="#4.11">4.11</A>) What is the Genetic Query Optimizer?<BR>
<A href="#4.13">4.13</A>) How do I perform regular expression <A href="#4.12">4.12</A>) How do I perform regular expression
searches and case-insensitive regular expression searches? How do I searches and case-insensitive regular expression searches? How do I
use an index for case-insensitive searches?<BR> use an index for case-insensitive searches?<BR>
<A href="#4.14">4.14</A>) In a query, how do I detect if a field <A href="#4.13">4.13</A>) In a query, how do I detect if a field
is <SMALL>NULL</SMALL>?<BR> is <SMALL>NULL</SMALL>?<BR>
<A href="#4.15">4.15</A>) What is the difference between the <A href="#4.14">4.14</A>) What is the difference between the
various character types?<BR> various character types?<BR>
<A href="#4.16.1">4.16.1</A>) How do I create a <A href="#4.15.1">4.15.1</A>) How do I create a
serial/auto-incrementing field?<BR> serial/auto-incrementing field?<BR>
<A href="#4.16.2">4.16.2</A>) How do I get the value of a <A href="#4.15.2">4.15.2</A>) How do I get the value of a
<SMALL>SERIAL</SMALL> insert?<BR> <SMALL>SERIAL</SMALL> insert?<BR>
<A href="#4.16.3">4.16.3</A>) Don't <I>currval()</I> and <A href="#4.15.3">4.15.3</A>) Don't <I>currval()</I> and
<I>nextval()</I> lead to a race condition with other users?<BR> <I>nextval()</I> lead to a race condition with other users?<BR>
<A href="#4.17">4.17</A>) What is an <SMALL>OID</SMALL>? What is a <A href="#4.16">4.16</A>) What is an <SMALL>OID</SMALL>? What is a
<SMALL>TID</SMALL>?<BR> <SMALL>TID</SMALL>?<BR>
<A href="#4.18">4.18</A>) What is the meaning of some of the terms <A href="#4.17">4.17</A>) What is the meaning of some of the terms
used in PostgreSQL?<BR> used in PostgreSQL?<BR>
<A href="#4.19">4.19</A>) Why do I get the error <I>"ERROR: <A href="#4.18">4.18</A>) Why do I get the error <I>"ERROR:
Memory exhausted in AllocSetAlloc()?"</I><BR> Memory exhausted in AllocSetAlloc()?"</I><BR>
<A href="#4.20">4.20</A>) How do I tell what PostgreSQL version I <A href="#4.19">4.19</A>) How do I tell what PostgreSQL version I
am running? <BR> am running? <BR>
<A href="#4.21">4.21</A>) My large-object operations get <A href="#4.20">4.20</A>) My large-object operations get
<I>invalid large obj descriptor.</I> Why?<BR> <I>invalid large obj descriptor.</I> Why?<BR>
<A href="#4.22">4.22</A>) How do I create a column that will <A href="#4.21">4.21</A>) How do I create a column that will
default to the current time?<BR> default to the current time?<BR>
<A href="#4.23">4.23</A>) Why are my subqueries using <A href="#4.22">4.22</A>) Why are my subqueries using
<CODE><SMALL>IN</SMALL></CODE> so slow?<BR> <CODE><SMALL>IN</SMALL></CODE> so slow?<BR>
<A href="#4.24">4.24</A>) How do I perform an outer join?<BR> <A href="#4.23">4.23</A>) How do I perform an outer join?<BR>
<A href="#4.25">4.25</A>) How do I perform queries using multiple databases?<BR> <A href="#4.24">4.24</A>) How do I perform queries using multiple databases?<BR>
<CENTER> <CENTER>
...@@ -788,22 +786,13 @@ ...@@ -788,22 +786,13 @@
<H2>Operational Questions</H2> <H2>Operational Questions</H2>
</CENTER> </CENTER>
<H4><A name="4.1">4.1</A>) Why is system confused about commas, <H4><A name="4.1">4.1</A>) What is the difference between
decimal points, and date formats.</H4>
<P>Check your locale configuration. PostgreSQL uses the locale
setting of the user that ran the <I>postmaster</I> process. There
are postgres and psql <SMALL>SET</SMALL> commands to control the
date format. Set those accordingly for your operating
environment.</P>
<H4><A name="4.2">4.2</A>) What is the exact difference between
binary cursors and normal cursors?</H4> binary cursors and normal cursors?</H4>
<P>See the <SMALL>DECLARE</SMALL> manual page for a <P>See the <SMALL>DECLARE</SMALL> manual page for a
description.</P> description.</P>
<H4><A name="4.3">4.3</A>) How do I <SMALL>SELECT</SMALL> only the <H4><A name="4.2">4.2</A>) How do I <SMALL>SELECT</SMALL> only the
first few rows of a query?</H4> first few rows of a query?</H4>
<P>See the <SMALL>FETCH</SMALL> manual page, or use <P>See the <SMALL>FETCH</SMALL> manual page, or use
...@@ -816,7 +805,7 @@ ...@@ -816,7 +805,7 @@
records requested, or the entire query may have to be evaluated records requested, or the entire query may have to be evaluated
until the desired rows have been generated.</P> until the desired rows have been generated.</P>
<H4><A name="4.4">4.4</A>) How do I get a list of tables or other <H4><A name="4.3">4.3</A>) How do I get a list of tables or other
things I can see in <I>psql?</I><BR> things I can see in <I>psql?</I><BR>
</H4> </H4>
...@@ -827,7 +816,7 @@ ...@@ -827,7 +816,7 @@
<I>-E</I> option so it will print out the queries it uses to <I>-E</I> option so it will print out the queries it uses to
execute the commands you give.</P> execute the commands you give.</P>
<H4><A name="4.5">4.5</A>) How do you remove a column from a <H4><A name="4.4">4.4</A>) How do you remove a column from a
table?</H4> table?</H4>
<P>We do not support <SMALL>ALTER TABLE DROP COLUMN,</SMALL> but do <P>We do not support <SMALL>ALTER TABLE DROP COLUMN,</SMALL> but do
...@@ -840,7 +829,7 @@ ...@@ -840,7 +829,7 @@
ALTER TABLE new_table RENAME TO old_table; ALTER TABLE new_table RENAME TO old_table;
</PRE> </PRE>
<H4><A name="4.6">4.6</A>) What is the maximum size for a row, <H4><A name="4.5">4.5</A>) What is the maximum size for a row,
table, database?</H4> table, database?</H4>
<P>These are the limits:</P> <P>These are the limits:</P>
...@@ -864,7 +853,7 @@ ...@@ -864,7 +853,7 @@
<P>The maximum table size and maximum number of columns can be <P>The maximum table size and maximum number of columns can be
increased if the default block size is increased to 32k.</P> increased if the default block size is increased to 32k.</P>
<H4><A name="4.7">4.7</A>) How much database disk space is required <H4><A name="4.6">4.6</A>) How much database disk space is required
to store data from a typical text file?<BR> to store data from a typical text file?<BR>
</H4> </H4>
...@@ -897,7 +886,7 @@ ...@@ -897,7 +886,7 @@
<P>Indexes do not require as much overhead, but do contain the data <P>Indexes do not require as much overhead, but do contain the data
that is being indexed, so they can be large also.</P> that is being indexed, so they can be large also.</P>
<H4><A name="4.8">4.8</A>) How do I find out what tables or indexes <H4><A name="4.7">4.7</A>) How do I find out what tables or indexes
are defined in the database?</H4> are defined in the database?</H4>
<P><I>psql</I> has a variety of backslash commands to show such <P><I>psql</I> has a variety of backslash commands to show such
...@@ -907,7 +896,7 @@ ...@@ -907,7 +896,7 @@
illustrates many of the <SMALL>SELECT</SMALL>s needed to get illustrates many of the <SMALL>SELECT</SMALL>s needed to get
information from the database system tables.</P> information from the database system tables.</P>
<H4><A name="4.9">4.9</A>) My queries are slow or don't make use of <H4><A name="4.8">4.8</A>) My queries are slow or don't make use of
the indexes. Why?</H4> the indexes. Why?</H4>
<P>PostgreSQL does not automatically maintain statistics. <P>PostgreSQL does not automatically maintain statistics.
...@@ -937,12 +926,12 @@ ...@@ -937,12 +926,12 @@
<I>~</I>(regular expression searches) should start with <I>~</I>(regular expression searches) should start with
<I>^.</I></P> <I>^.</I></P>
<H4><A name="4.10">4.10</A>) How do I see how the query optimizer <H4><A name="4.9">4.9</A>) How do I see how the query optimizer
is evaluating my query?</H4> is evaluating my query?</H4>
<P>See the <SMALL>EXPLAIN</SMALL> manual page.</P> <P>See the <SMALL>EXPLAIN</SMALL> manual page.</P>
<H4><A name="4.11">4.11</A>) What is an R-tree index?</H4> <H4><A name="4.10">4.10</A>) What is an R-tree index?</H4>
<P>An R-tree index is used for indexing spatial data. A hash index <P>An R-tree index is used for indexing spatial data. A hash index
can't handle range searches. A B-tree index only handles range can't handle range searches. A B-tree index only handles range
...@@ -967,7 +956,7 @@ ...@@ -967,7 +956,7 @@
practice, extending R-trees requires a bit of work and we don't practice, extending R-trees requires a bit of work and we don't
currently have any documentation on how to do it.</P> currently have any documentation on how to do it.</P>
<H4><A name="4.12">4.12</A>) What is the Genetic Query <H4><A name="4.11">4.11</A>) What is the Genetic Query
Optimizer?</H4> Optimizer?</H4>
<P>The <SMALL>GEQO</SMALL> module speeds query optimization when <P>The <SMALL>GEQO</SMALL> module speeds query optimization when
...@@ -975,7 +964,7 @@ ...@@ -975,7 +964,7 @@
the handling of large join queries through nonexhaustive the handling of large join queries through nonexhaustive
search.</P> search.</P>
<H4><A name="4.13">4.13</A>) How do I perform regular expression <H4><A name="4.12">4.12</A>) How do I perform regular expression
searches and case-insensitive regular expression searches? How do I searches and case-insensitive regular expression searches? How do I
use an index for case-insensitive searches?</H4> use an index for case-insensitive searches?</H4>
...@@ -999,12 +988,12 @@ ...@@ -999,12 +988,12 @@
CREATE INDEX tabindex on tab (lower(col)); CREATE INDEX tabindex on tab (lower(col));
</PRE> </PRE>
<H4><A name="4.14">4.14</A>) In a query, how do I detect if a field <H4><A name="4.13">4.13</A>) In a query, how do I detect if a field
is <SMALL>NULL</SMALL>?</H4> is <SMALL>NULL</SMALL>?</H4>
<P>You test the column with <SMALL>IS NULL</SMALL>IS NOT NULL.</P> <P>You test the column with <SMALL>IS NULL</SMALL>IS NOT NULL.</P>
<H4><A name="4.15">4.15</A>) What is the difference between the <H4><A name="4.14">4.14</A>) What is the difference between the
various character types?</H4> various character types?</H4>
<PRE> <PRE>
Type Internal Name Notes Type Internal Name Notes
...@@ -1034,7 +1023,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1034,7 +1023,7 @@ BYTEA bytea variable-length byte array (null-safe)
binary data, particularly values that include <SMALL>NULL</SMALL> binary data, particularly values that include <SMALL>NULL</SMALL>
bytes.</P> bytes.</P>
<H4><A name="4.16.1">4.16.1</A>) How do I create a <H4><A name="4.15.1">4.15.1</A>) How do I create a
serial/auto-incrementing field?</H4> serial/auto-incrementing field?</H4>
<P>PostgreSQL supports a <SMALL>SERIAL</SMALL> data type. It <P>PostgreSQL supports a <SMALL>SERIAL</SMALL> data type. It
...@@ -1064,13 +1053,13 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1064,13 +1053,13 @@ BYTEA bytea variable-length byte array (null-safe)
<P><A href="http://www.PostgreSQL.org/docs/aw_pgsql_book">Numbering <P><A href="http://www.PostgreSQL.org/docs/aw_pgsql_book">Numbering
Rows.</A></P> Rows.</A></P>
<H4><A name="4.16.2">4.16.2</A>) How do I get the value of a <H4><A name="4.15.2">4.15.2</A>) How do I get the value of a
<SMALL>SERIAL</SMALL> insert?</H4> <SMALL>SERIAL</SMALL> insert?</H4>
<P>One approach is to to retrieve the next <SMALL>SERIAL</SMALL> <P>One approach is to to retrieve the next <SMALL>SERIAL</SMALL>
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.15.1">4.15.1</A>, that might look like
this in Perl:</P> this in Perl:</P>
<PRE> <PRE>
new_id = output of "SELECT nextval('person_id_seq')" new_id = output of "SELECT nextval('person_id_seq')"
...@@ -1091,20 +1080,20 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1091,20 +1080,20 @@ BYTEA bytea variable-length byte array (null-safe)
INSERT INTO person (name) VALUES ('Blaise Pascal'); INSERT INTO person (name) VALUES ('Blaise Pascal');
new_id = output of "SELECT currval('person_id_seq')"; new_id = output of "SELECT currval('person_id_seq')";
</PRE> </PRE>
Finally, you could use the <A href="#4.17"><SMALL>OID</SMALL></A> Finally, you could use the <A href="#4.16"><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
default value, though this is probably the least portable approach. default value, though this is probably the least portable approach.
In Perl, using DBI with Edmund Mergl's DBD::Pg module, the oid In Perl, using DBI with Edmund Mergl's DBD::Pg module, the oid
value is made available via <I>$sth-&gt;{pg_oid_status} after value is made available via <I>$sth-&gt;{pg_oid_status} after
$sth-&gt;execute().</I> $sth-&gt;execute().</I>
<H4><A name="4.16.3">4.16.3</A>) Don't <I>currval()</I> and <H4><A name="4.15.3">4.15.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. Currval() returns the current value assigned by your <P>No. Currval() returns the current value assigned by your
backend, not by all users.</P> 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.16">4.16</A>) What is an <SMALL>OID</SMALL>? What is
a <SMALL>TID</SMALL>?</H4> a <SMALL>TID</SMALL>?</H4>
<P><SMALL>OID</SMALL>s are PostgreSQL's answer to unique row ids. <P><SMALL>OID</SMALL>s are PostgreSQL's answer to unique row ids.
...@@ -1149,7 +1138,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1149,7 +1138,7 @@ BYTEA bytea variable-length byte array (null-safe)
or reloaded. They are used by index entries to point to physical or reloaded. They are used by index entries to point to physical
rows.</P> rows.</P>
<H4><A name="4.18">4.18</A>) What is the meaning of some of the <H4><A name="4.17">4.17</A>) What is the meaning of some of the
terms used in PostgreSQL?</H4> terms used in PostgreSQL?</H4>
<P>Some of the source code and older documentation use terms that <P>Some of the source code and older documentation use terms that
...@@ -1178,7 +1167,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1178,7 +1167,7 @@ BYTEA bytea variable-length byte array (null-safe)
<P>A list of general database terms can be found at: <A href= <P>A list of general database terms can be found at: <A href=
"http://www.comptechnews.com/~reaster/dbdesign.html">http://www.comptechnews.com/~reaster/dbdesign.html</A></P> "http://www.comptechnews.com/~reaster/dbdesign.html">http://www.comptechnews.com/~reaster/dbdesign.html</A></P>
<H4><A name="4.19">4.19</A>) Why do I get the error <I>"ERROR: <H4><A name="4.18">4.18</A>) Why do I get the error <I>"ERROR:
Memory exhausted in AllocSetAlloc()?"</I><BR> Memory exhausted in AllocSetAlloc()?"</I><BR>
</H4> </H4>
...@@ -1198,13 +1187,13 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1198,13 +1187,13 @@ BYTEA bytea variable-length byte array (null-safe)
backend is returning too much data, try it before starting the backend is returning too much data, try it before starting the
client. client.
<H4><A name="4.20">4.20</A>) How do I tell what PostgreSQL version <H4><A name="4.19">4.19</A>) How do I tell what PostgreSQL version
I am running?<BR> I am running?<BR>
</H4> </H4>
<P>From <I>psql,</I> type <CODE>select version();</CODE></P> <P>From <I>psql,</I> type <CODE>select version();</CODE></P>
<H4><A name="4.21">4.21</A>) My large-object operations get <H4><A name="4.20">4.20</A>) My large-object operations get
<I>invalid large obj descriptor.</I> Why?<BR> <I>invalid large obj descriptor.</I> Why?<BR>
</H4> </H4>
...@@ -1221,7 +1210,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1221,7 +1210,7 @@ BYTEA bytea variable-length byte array (null-safe)
<P>If you are using a client interface like <SMALL>ODBC</SMALL> you <P>If you are using a client interface like <SMALL>ODBC</SMALL> you
may need to set <CODE>auto-commit off.</CODE></P> may need to set <CODE>auto-commit off.</CODE></P>
<H4><A name="4.22">4.22</A>) How do I create a column that will <H4><A name="4.21">4.21</A>) How do I create a column that will
default to the current time?<BR> default to the current time?<BR>
</H4> </H4>
...@@ -1231,7 +1220,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1231,7 +1220,7 @@ BYTEA bytea variable-length byte array (null-safe)
</CODE> </CODE>
</PRE> </PRE>
<H4><A name="4.23">4.23</A>) Why are my subqueries using <H4><A name="4.22">4.22</A>) Why are my subqueries using
<CODE><SMALL>IN</SMALL></CODE> so slow?<BR> <CODE><SMALL>IN</SMALL></CODE> so slow?<BR>
</H4> </H4>
...@@ -1254,7 +1243,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1254,7 +1243,7 @@ BYTEA bytea variable-length byte array (null-safe)
</PRE> </PRE>
We hope to fix this limitation in a future release. We hope to fix this limitation in a future release.
<H4><A name="4.24">4.24</A>) How do I perform an outer join?<BR> <H4><A name="4.23">4.23</A>) How do I perform an outer join?<BR>
</H4> </H4>
<P>PostgreSQL 7.1 and later supports outer joins using the SQL <P>PostgreSQL 7.1 and later supports outer joins using the SQL
...@@ -1295,7 +1284,7 @@ BYTEA bytea variable-length byte array (null-safe) ...@@ -1295,7 +1284,7 @@ BYTEA bytea variable-length byte array (null-safe)
ORDER BY col1 ORDER BY col1
</PRE> </PRE>
<H4><A href="#4.25">4.25</A>) How do I perform queries <H4><A href="#4.24">4.24</A>) How do I perform queries
using multiple databases?</H4> using multiple databases?</H4>
<P>There is no way to query any database except the current one. <P>There is no way to query any database except the current one.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment