</refsect1>
</refentry>
+
+<REFENTRY ID="SQL-CREATETABLEAS">
+ <REFMETA>
+ <REFENTRYTITLE>
+ CREATE TABLE
+ </REFENTRYTITLE>
+ <REFMISCINFO>SQL - Language Statements</REFMISCINFO>
+ </REFMETA>
+ <REFNAMEDIV>
+ <REFNAME>
+ CREATE TABLE
+ </REFNAME>
+ <REFPURPOSE>
+ Creates a new table
+ </REFPURPOSE>
+
+ <REFSYNOPSISDIV>
+ <REFSYNOPSISDIVINFO>
+ <DATE>1998-09-22</DATE>
+ </REFSYNOPSISDIVINFO>
+ <SYNOPSIS>
+CREATE TABLE <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE> [ ( <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> [, ...] ) ] AS <REPLACEABLE CLASS="PARAMETER">select_clause</REPLACEABLE>
+ </SYNOPSIS>
+
+ <REFSECT2 ID="R2-SQL-CREATETABLEAS-1">
+ <REFSECT2INFO>
+ <DATE>1998-09-22</DATE>
+ </REFSECT2INFO>
+ <TITLE>
+ Inputs
+ </TITLE>
+ <PARA>
+
+ <VARIABLELIST>
+ <VARLISTENTRY>
+ <TERM>
+ <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE>
+ </TERM>
+ <LISTITEM>
+ <PARA>
+ The name of a new table to be created.
+ </PARA>
+ </LISTITEM>
+ </VARLISTENTRY>
+
+ <VARLISTENTRY>
+ <TERM>
+ <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE>
+ </TERM>
+ <LISTITEM>
+ <PARA>
+ The name of a column. Multiple column names can be specified using
+a comma-delimited list of column names.
+ </PARA>
+ </LISTITEM>
+ </VARLISTENTRY>
+
+ <VARLISTENTRY>
+ <TERM>
+ <REPLACEABLE CLASS="PARAMETER">select_clause</REPLACEABLE>
+ </TERM>
+ <LISTITEM>
+ <PARA>
+A valid query statement. Refer to SELECT for a description of the
+allowed syntax.
+ </PARA>
+ </LISTITEM>
+ </VARLISTENTRY>
+ </VARIABLELIST>
+
+ <REFSECT2 ID="R2-SQL-CREATETABLEAS-2">
+ <REFSECT2INFO>
+ <DATE>1998-09-22</DATE>
+ </REFSECT2INFO>
+ <TITLE>
+ Outputs
+ </TITLE>
+ <PARA>
+ Refer to CREATE TABLE and SELECT for a summary of possible output
+messages.
+
+ <REFSECT1 ID="R1-SQL-CREATETABLEAS-1">
+ <REFSECT1INFO>
+ <DATE>1998-09-22</DATE>
+ </REFSECT1INFO>
+ <TITLE>
+ Description
+ </TITLE>
+ <PARA>
+CREATE TABLE AS enables a table to be created from the contents of
+an existing table. It has functionality equivalent to SELECT TABLE INTO,
+but with perhaps a more obvious syntax.
+
+</refsect1>
+</refentry>
+
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
EXPLAIN
</REFNAME>
<REFPURPOSE>
-Shows statement execution details.
+Shows statement execution details
</REFPURPOSE>
<REFSYNOPSISDIV>
<VARLISTENTRY>
<TERM>
NOTICE: QUERY PLAN:
+<replaceable>plan</replaceable>
</TERM>
<LISTITEM>
<PARA>
Explicit query plan from the <productname>Postgres</productname> backend.
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
<VARLISTENTRY>
<TERM>
EXPLAIN
<PARA>
Flag sent after query plan is shown.
+</VARIABLELIST>
</VARIABLELIST>
</REFSECT2>
Notes
</TITLE>
<PARA>
+There is only sparse documentation on the optimizer's use of cost
+information in <productname>Postgres</productname>.
+General information on cost estimation for query optimization
+can be found in database textbooks.
+Refer to the <citetitle>Programmer's Guide</citetitle>
+in the chapters on indexes and the genetic query optimizer for
+more information.
</REFSECT2>
</TERM>
<LISTITEM>
<PARA>
-If <REPLACEABLE CLASS="PARAMETER">cursor</REPLACEABLE> is not previously declared.
+If <REPLACEABLE CLASS="PARAMETER">cursor</REPLACEABLE>
+ is not previously declared.
The cursor must be declared within a transaction block.
<VARLISTENTRY>
Compatibility
</TITLE>
<PARA>
+The non-embedded use of cursors is a <productname>Postgres</productname>
+extension. The syntax and usage of cursors is being compared
+against the embedded form of cursors defined in <acronym>SQL92</acronym>.
</PARA>
<REFSECT2 ID="R2-SQL-FETCH-4">
SQL92
</TITLE>
<PARA>
-SQL92 allows absolute positioning of the cursor for
+<acronym>SQL92</acronym> allows absolute positioning of the cursor for
FETCH, and allows placing the results into explicit variables.
<synopsis>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-23</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
GRANT <REPLACEABLE CLASS="PARAMETER">privilege</REPLACEABLE> [, ...]
<REFSECT2 ID="R2-SQL-GRANT-1">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-23</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
<REFSECT2 ID="R2-SQL-GRANT-2">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-23</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
to give privileges to the specified group or users.
</VARIABLELIST>
+</VARIABLELIST>
</REFSECT2>
</REFSYNOPSISDIV>
<REFSECT1 ID="R1-SQL-GRANT-1">
<REFSECT1INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-23</DATE>
</REFSECT1INFO>
<TITLE>
Description
<REFSECT2 ID="R2-SQL-GRANT-3">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-23</DATE>
</REFSECT2INFO>
<TITLE>
Notes
Currently, to create a GROUP you have to insert
data manually into table pg_group as:
<programlisting>
- INSERT INTO pg_group VALUES ('todos');
- CREATE USER miriam IN GROUP todos;
+INSERT INTO pg_group VALUES ('todos');
+CREATE USER miriam IN GROUP todos;
</programlisting>
Refer to REVOKE statements to revoke access privileges.
</tip>
</TITLE>
<PARA>
<ProgramListing>
- -- grant insert privilege to all users on table films:
- --
- GRANT INSERT ON films TO PUBLIC;
+-- grant insert privilege to all users on table films:
+--
+GRANT INSERT ON films TO PUBLIC;
</programlisting>
<programlisting>
- -- grant all privileges to user manuel on view kinds:
- --
- GRANT ALL ON kinds TO manuel;
+-- grant all privileges to user manuel on view kinds:
+--
+GRANT ALL ON kinds TO manuel;
</ProgramListing>
</REFSECT1>
<REFSECT2 ID="R2-SQL-GRANT-4">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-23</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
</TITLE>
<PARA>
- The SQL92 syntax for GRANT allows setting privileges
+ The <acronym>SQL92</acronym> syntax for GRANT allows setting privileges
for individual columns
within a table, and allows setting a privilege to grant
the same privileges to others.
</REFPURPOSE>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-02</DATE>
+<DATE>1998-09-23</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
INSERT INTO <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE> [ ( <REPLACEABLE CLASS="PARAMETER">column</REPLACEABLE> [, ...] ) ]
<REFSECT2 ID="R2-SQL-INSERT-1">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-23</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
<REFSECT2 ID="R2-SQL-INSERT-2">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-23</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
-INSERT <ReturnValue>oid</ReturnValue> 1
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<ReturnValue>INSERT <replaceable>oid</replaceable></ReturnValue> 1
</TERM>
<LISTITEM>
<PARA>
Message returned if only one row was inserted.
-<ReturnValue>oid</ReturnValue> is the row identifier.
+<ReturnValue><replaceable>oid</replaceable></ReturnValue>
+ is the row identifier.
<VARLISTENTRY>
<TERM>
-INSERT 0 <ReturnValue>#</ReturnValue>
+<ReturnValue>INSERT 0 <replaceable>#</replaceable></ReturnValue>
</TERM>
<LISTITEM>
<PARA>
Message returned if more than one rows were inserted.
-<ReturnValue>#</ReturnValue> is the number of rows inserted.
+<ReturnValue><replaceable>#</replaceable></ReturnValue>
+ is the number of rows inserted.
</VARIABLELIST>
+</VARIABLELIST>
</REFSECT2>
</REFSYNOPSISDIV>
</TITLE>
<PARA>
<ProgramListing>
- --Insert a single row into table films;
- --(in the second example the column date_prod is omitted
- --therefore will be stored in it a default value of NULL):
- --
- INSERT INTO films VALUES
- ('UA502','Bananas',105,'1971-07-13','Comedy',INTERVAL '82 minute');
-
- INSERT INTO films (code, title, did, date_prod, kind)
- VALUES ('T_601', 'Yojimbo', 106, DATE '1961-06-16', 'Drama');
+--Insert a single row into table films;
+--(in the second example the column date_prod is omitted
+--therefore will be stored in it a default value of NULL):
+--
+INSERT INTO films VALUES
+ ('UA502','Bananas',105,'1971-07-13','Comedy',INTERVAL '82 minute');
+
+INSERT INTO films (code, title, did, date_prod, kind)
+ VALUES ('T_601', 'Yojimbo', 106, DATE '1961-06-16', 'Drama');
</ProgramListing>
<ProgramListing>
- --Insert a single row into table distributors, note that
- --only column "name" is specified, to the non specified
- --column "did" will be assigned its default value:
- --
- INSERT INTO distributors (name) VALUES ('British Lion');
+--Insert a single row into table distributors, note that
+--only column "name" is specified, to the non specified
+--column "did" will be assigned its default value:
+--
+INSERT INTO distributors (name) VALUES ('British Lion');
</ProgramListing>
<ProgramListing>
- --Insert several rows into table films from table tmp:
- --
- INSERT INTO films
- SELECT * FROM tmp;
+--Insert several rows into table films from table tmp:
+--
+INSERT INTO films
+ SELECT * FROM tmp;
</ProgramListing>
<ProgramListing>
- --Insert into arrays:
- --Create an empty 3x3 gameboard for noughts-and-crosses
- --(all of these queries create the same board attribute)
- --(Refer to PostgreSQL User's Guide chapter 7 for further
- --information about arrays).
-
- INSERT INTO tictactoe (game, board[1:3][1:3])
- VALUES (1,'{{"","",""},{},{"",""}}');
- INSERT INTO tictactoe (game, board[3][3])
- VALUES (2,'{}');
- INSERT INTO tictactoe (game, board)
- VALUES (3,'{{,,},{,,},{,,}}');
+--Insert into arrays:
+--Create an empty 3x3 gameboard for noughts-and-crosses
+--(all of these queries create the same board attribute)
+--(Refer to the <citetitle>PostgreSQL User's Guide</citetitle> for further
+--information about arrays).
+
+INSERT INTO tictactoe (game, board[1:3][1:3])
+ VALUES (1,'{{"","",""},{},{"",""}}');
+INSERT INTO tictactoe (game, board[3][3])
+ VALUES (2,'{}');
+INSERT INTO tictactoe (game, board)
+ VALUES (3,'{{,,},{,,},{,,}}');
</ProgramListing>
</REFSECT1>
<REFSECT2 ID="R2-SQL-INSERT-4">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-23</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
LISTEN <REPLACEABLE CLASS="PARAMETER">classname</REPLACEABLE>
<REFSECT2 ID="R2-SQL-LISTEN-2">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
+
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<PARA>
Message returned upon successful completion of registration.
+</VARIABLELIST>
</VARIABLELIST>
</REFSECT2>
<REFSECT1 ID="R1-SQL-LISTEN-1">
<REFSECT1INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
<REFSECT2 ID="R2-SQL-LISTEN-3">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
</TITLE>
<para>
Note that <REPLACEABLE CLASS="PARAMETER">classname</REPLACEABLE>
-needs not to be a valid class name but can be any string valid as a name up to 32
-characters long.
+needs not to be a valid class name but can be any string valid
+ as a name up to 32 characters long.
<para>
A restriction in some previous releases of
Compatibility
</TITLE>
<PARA>
-</PARA>
<REFSECT2 ID="R2-SQL-LISTEN-4">
<REFSECT2INFO>
SQL92
</TITLE>
<PARA>
- There is no LISTEN statement in <acronym>SQL92</acronym>.
+ There is no <command>LISTEN</command> in <acronym>SQL92</acronym>.
</REFENTRY>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
<REPLACEABLE CLASS="PARAMETER">
<REFSECT2 ID="R2-SQL-LOAD-2">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
-LOAD
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
+
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<returnvalue>LOAD</returnvalue>
</TERM>
<LISTITEM>
<PARA>
+Message returned on successful completion.
+<VARLISTENTRY>
+<TERM>
+<returnvalue>ERROR: LOAD: could not open file '<REPLACEABLE CLASS="PARAMETER">filename</REPLACEABLE>'</returnvalue>
+</TERM>
+<LISTITEM>
+<PARA>
+Message returned if the specified file is not found. The file must be visible
+<emphasis>to the <productname>Postgres</productname> backend</emphasis>,
+with the appropriate full path name specified, to avoid this message.
+
+</VARIABLELIST>
</VARIABLELIST>
</REFSECT2>
<REFSECT1 ID="R1-SQL-LOAD-1">
<REFSECT1INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
Loads an object (or ".o") file into the
<productname>Postgres</productname> backend address space. Once a
file is loaded, all functions in that file can be accessed. This
-function is used in support of ADT's.
+function is used in support of user-defined types and functions.
<para>
If a file is not loaded using
<REFSECT2 ID="R2-SQL-LOAD-3">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
Functions in loaded object files should not call functions in other
object files loaded through the
<command>LOAD</command>
-command, meaning, for example, that all functions in file A should
+command. For example, all functions in file <literal>A</literal> should
call each other, functions in the standard or math libraries, or in
Postgres itself. They should not call functions defined in a different
-loaded file B. This is because if B is reloaded, the Postgres loader is
-not able to relocate the calls from the functions in A into
-the new address space of B. If B is not reloaded, however, there will
+loaded file <literal>B</literal>.
+ This is because if <literal>B</literal> is reloaded, the Postgres loader is
+not able to relocate the calls from the functions in <literal>A</literal> into
+the new address space of <literal>B</literal>.
+If <literal>B</literal> is not reloaded, however, there will
not be a problem.
<para>
For example,
on DECstations you must use
<application>/bin/cc</application>
-with the "-G 0" option when compiling object files to be
+with the <literal>-G 0</literal> option when compiling object files to be
loaded.
<para>
</TITLE>
<PARA>
<ProgramListing>
- --Load the file /usr/postgres/demo/circle.o
- --
- LOAD "/usr/postgres/demo/circle.o"
+--Load the file /usr/postgres/demo/circle.o
+--
+LOAD "/usr/postgres/demo/circle.o"
</ProgramListing>
</REFSECT1>
<REFSECT2 ID="R2-SQL-LOAD-4">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
</TITLE>
<PARA>
-There is no LOAD statement in <acronym>SQL92</acronym>.
+There is no <command>LOAD</command> in <acronym>SQL92</acronym>.
</REFENTRY>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
-LOCK [TABLE] <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE>
+LOCK [ TABLE ] <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE>
</SYNOPSIS>
<REFSECT2 ID="R2-SQL-LOCK-1">
<REFSECT2 ID="R2-SQL-LOCK-2">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
+
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
</TERM>
<LISTITEM>
<PARA>
-Message returned if table don't exist.
+Message returned if <REPLACEABLE CLASS="PARAMETER">table</REPLACEABLE>
+ does not exist.
</VARIABLELIST>
+</VARIABLELIST>
</REFSECT2>
</REFSYNOPSISDIV>
<REFSECT1 ID="R1-SQL-LOCK-1">
<REFSECT1INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
- The LOCK statement locks in exclusive mode a table inside
+ <command>LOCK</command> locks in exclusive mode a table inside
a transaction. The classic use for this is
the case where you want to select some data, then
update it inside a transaction.
If you don't explicit lock a table using LOCK statement, it will be
- implicit locked only at first UPDATE, INSERT or DELETE operation.
+ implicit locked only at the first
+ <command>UPDATE</command>, <command>INSERT</command>,
+ or <command>DELETE</command> operation.
If you don't exclusive lock the table before the select, some
other user may also read the selected data, and try and do
their own update, causing a deadlock while you both wait
the tables to become available. The only solution to this
is for both users to lock tables in the same order, so
user's lock acquisitions and requests to not form a deadlock.
-
+
+<note>
+<para>
+<productname>Postgres</productname> does detect deadlocks and will
+rollback transactions to resolve the deadlock. Usually, at least one
+of the deadlocked transactions will complete successfully.
+</note>
+
<REFSECT2 ID="R2-SQL-LOCK-3">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
</TITLE>
<PARA>
-LOCK is a PostgreSQL language extension.
+<command>LOCK</command> is a <productname>Postgres</productname>
+ language extension.
<para>
-LOCK works only inside transactions.
+<command>LOCK</command> works only inside transactions.
<note>
<title>Bug</title>
<PARA>
</PARA>
<ProgramListing>
- --Explicit locking to prevent deadlock:
- --
- BEGIN WORK;
- LOCK films;
- SELECT * FROM films;
- UPDATE films SET len = INTERVAL '100 minute'
- WHERE len = INTERVAL '117 minute';
- COMMIT WORK;
+--Explicit locking to prevent deadlock:
+--
+BEGIN WORK;
+ LOCK films;
+ SELECT * FROM films;
+ UPDATE films SET len = INTERVAL '100 minute'
+ WHERE len = INTERVAL '117 minute';
+COMMIT WORK;
</ProgramListing>
</REFSECT1>
Compatibility
</TITLE>
<PARA>
-</PARA>
<REFSECT2 ID="R2-SQL-LOCK-4">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
</TITLE>
<PARA>
There is no <command>LOCK TABLE</command> in <acronym>SQL92</acronym>,
- it uses SET TRANSACTION to specify
+ which instead uses <command>SET TRANSACTION</command> to specify
concurrency level on transactions.
+
</REFENTRY>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
MOVE [ <REPLACEABLE CLASS="PARAMETER">selector</REPLACEABLE> ] [ <REPLACEABLE CLASS="PARAMETER">count</REPLACEABLE> ]
<REFSECT1 ID="R1-SQL-MOVE-1">
<REFSECT1INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
- MOVE allows a user to move cursor position a specified
- number of rows. MOVE works like the FETCH command, but only
-positions the cursor and does
+ <command>MOVE</command> allows a user to move cursor position a specified
+ number of rows.
+ <command>MOVE</command> works like the <command>FETCH</command> command,
+ but only positions the cursor and does
not return rows.
<para>
-Refer to the FETCH command for details on syntax and usage.
+Refer to the <command>FETCH</command> command for details on syntax and usage.
<REFSECT2 ID="R2-SQL-MOVE-3">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
</TITLE>
<PARA>
-MOVE is a <productname>Postgres</productname> language extension.
+<command>MOVE</command> is a <productname>Postgres</productname>
+ language extension.
<para>
- Refer to FETCH for a description
+ Refer to <command>FETCH</command> for a description
of valid arguments.
- Refer to DECLARE to declare a cursor.
- Refer to BEGIN WORK, COMMIT WORK, ROLLBACK WORK statements
+ Refer to <command>DECLARE</command> to declare a cursor.
+ Refer to <command>BEGIN WORK</command>, <command>COMMIT WORK</command>,
+ <command>ROLLBACK WORK</command> statements
for further information about transactions.
</REFSECT2>
</TITLE>
<PARA>
<ProgramListing>
- --set up and use a cursor:
- --
- BEGIN WORK;
- DECLARE liahona CURSOR
- FOR SELECT * FROM films;
-
- --Skip first 5 rows:
- --
- MOVE FORWARD 5 IN liahona;
+--set up and use a cursor:
+--
+BEGIN WORK;
+ DECLARE liahona CURSOR FOR SELECT * FROM films;
- --Fetch 6th row in the cursor liahona:
- --
- FETCH 1 IN liahona;
-
- code |title |did| date_prod|kind |len
- -----+------+---+----------+----------+------
- P_303|48 Hrs|103|1982-10-22|Action | 01:37
-
- -- close the cursor liahona and commit work:
- --
- CLOSE liahona;
- COMMIT WORK;
+ --Skip first 5 rows:
+ --
+ MOVE FORWARD 5 IN liahona;
+<computeroutput>
+MOVE
+</computeroutput>
+ --Fetch 6th row in the cursor liahona:
+ --
+ FETCH 1 IN liahona;
+<computeroutput>
+FETCH
+code |title |did| date_prod|kind |len
+-----+------+---+----------+----------+------
+P_303|48 Hrs|103|1982-10-22|Action | 01:37
+(1 row)
+</computeroutput>
+ -- close the cursor liahona and commit work:
+ --
+ CLOSE liahona;
+COMMIT WORK;
</ProgramListing>
</REFSECT1>
SQL92
</TITLE>
<PARA>
- There is no SQL92 MOVE statement. Instead, <acronym>SQL92</acronym> allows
-one to FETCH rows from an absolute cursor position.
+ There is no SQL92 <command>MOVE</command> statement.
+Instead, <acronym>SQL92</acronym> allows
+one to <command>FETCH</command> rows from an absolute cursor position,
+implicitly moving the cursor to the correct place.
+
</REFENTRY>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
<REPLACEABLE CLASS="PARAMETER">
<REFSECT2 ID="R2-SQL-NOTIFY-1">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
</TITLE>
<PARA>
-</PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<REFSECT2 ID="R2-SQL-NOTIFY-2">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
+
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<PARA>
Notification message from backend.
+</VARIABLELIST>
</VARIABLELIST>
</REFSECT2>
<REFSECT1 ID="R1-SQL-NOTIFY-1">
<REFSECT1INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
- NOTIFY is used to awaken all backends and consequently all
- frontends that have executed <command>LISTEN</command> on
-<replaceable class="parameter">classname</replaceable>.
+ <command>NOTIFY</command> is used to awaken all sessions which have
+previously executed
+ <command>LISTEN <replaceable class="parameter">classname</replaceable></command>.
This can be used either within an instance-level rule
as part of the action body or from a normal query.
<para>
When used from within a normal query,
this can be thought of as interprocess communication (IPC). When
-used from within a rule, this can be thought of as an alerter mechanism.
+used from within a rule, this can be thought of as an alert mechanism.
<para>
- Notice that the mere fact that a notify has been
+ Note that the mere fact that a <command>NOTIFY</command> has been
executed does not imply anything in particular about the state
of the class (e.g., that it has been updated),
nor does the notification protocol transmit any useful information
other than the class name.
-Therefore, all notify does is indicate that some backend wishes its peers to
+Therefore, all <command>NOTIFY</command> does is indicate that some backend
+ wishes its peers to
examine <replaceable class="parameter">classname</replaceable>
in some application-specific way.
<para>
<para>
This event notification is performed through the libpq protocol
and frontend application interface. The application program
- must call the routine <function>PQnotifies</function> in order to find out the
-name of the class to which a given
+ must call the routine <function>PQnotifies</function>
+ in order to find out the name of the class to which a given
notification corresponds.
If this code is not included in the application,
the event notification will be
<REFSECT2 ID="R2-SQL-NOTIFY-3">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
<ProgramListing>
-- Configure and execute a listen/notify sequence
-- from psql
-postgres=> create table t (i int4);
-postgres=> listen t;
-LISTEN
-postgres=> notify t;
+CREATE TABLE t (i int4);
+<computeroutput>
+LISTEN t;
+</computeroutput>
+NOTIFY t;
+<computeroutput>
NOTIFY
ASYNC NOTIFY of 't' from backend pid '10949' received
+</computeroutput>
</ProgramListing>
</REFSECT1>
Compatibility
</TITLE>
<PARA>
-</PARA>
+
<REFSECT2 ID="R2-SQL-NOTIFY-4">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
</TITLE>
<PARA>
-There is no NOTIFY statement in <acronym>SQL92</acronym>.
+There is no <command>NOTIFY</command> statement in <acronym>SQL92</acronym>.
</REFENTRY>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
RESET <REPLACEABLE CLASS="PARAMETER">variable</REPLACEABLE>
<REFSECT2 ID="R2-SQL-RESET-1">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
</TITLE>
<PARA>
-</PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<REFSECT2 ID="R2-SQL-RESET-2">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
+
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
<VARIABLELIST>
<VARLISTENTRY>
</TERM>
<LISTITEM>
<PARA>
- Message returned if successfully.
+ Message returned if
+<REPLACEABLE CLASS="PARAMETER">variable</REPLACEABLE> is successfully reset
+to its default value..
+</VARIABLELIST>
</VARIABLELIST>
</REFSECT2>
<REFSECT1 ID="R1-SQL-RESET-1">
<REFSECT1INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
- The RESET statement restores variables to the default values.
-Refer to the SET command for details on allowed values and defaults.
-RESET is an alternate form for
+ <command>RESET</command> restores variables to the
+ default values.
+Refer to the <command>SET</command> command for details on
+ allowed values and defaults.
+<command>RESET</command> is an alternate form for
<synopsis>
<command>SET <replaceable class="parameter">variable</replaceable> = DEFAULT</command>
</synopsis>
<REFSECT2 ID="R2-SQL-RESET-3">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
</TITLE>
<PARA>
<ProgramListing>
- -- reset DateStyle to its default;
- RESET DateStyle;
+-- reset DateStyle to its default;
+RESET DateStyle;
</programlisting>
<programlisting>
- -- reset Geqo to its default;
- RESET GEQO;
+-- reset Geqo to its default;
+RESET GEQO;
</ProgramListing>
</REFSECT1>
Compatibility
</TITLE>
<PARA>
-</PARA>
<REFSECT2 ID="R2-SQL-RESET-4">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
</TITLE>
<PARA>
- There is no RESET statement in SQL92.
-</REFENTRY>
+ There is no <command>RESET</command> in <acronym>SQL92</acronym>.
-<!--
-<REPLACEABLE CLASS="PARAMETER">
-</REPLACEABLE>
-<ReturnValue></ReturnValue>
-<PARA>
-</PARA>
-<VARIABLELIST>
-<VARLISTENTRY>
-<TERM>•
-</TERM>
-<LISTITEM>
-<PARA>
-</PARA>
-</LISTITEM>
-</VARLISTENTRY>
-</VARIABLELIST>
-<PARA>
-</PARA>
--->
+</REFENTRY>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
<REPLACEABLE CLASS="PARAMETER">
<REFSECT2 ID="R2-SQL-REVOKE-1">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
</TITLE>
<PARA>
-</PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<LISTITEM>
<PARA>
Privilege to define rules on table/view.
-(See the <command>CREATE RULE</command> statement).
+(See <command>CREATE RULE</command>).
<VARLISTENTRY>
<TERM>
<REFSECT2 ID="R2-SQL-REVOKE-2">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
+
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
<VARIABLELIST>
<VARLISTENTRY>
to revoke privileges from a group or users.
</VARIABLELIST>
+</VARIABLELIST>
</REFSECT2>
</REFSYNOPSISDIV>
<REFSECT1 ID="R1-SQL-REVOKE-1">
<REFSECT1INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
<REFSECT2 ID="R2-SQL-REVOKE-3">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
</TITLE>
<PARA>
<ProgramListing>
- -- revoke insert privilege from all users on table films:
- --
- REVOKE INSERT ON films FROM PUBLIC;
+-- revoke insert privilege from all users on table films:
+--
+REVOKE INSERT ON films FROM PUBLIC;
- -- revoke all privileges from user manuel on view kinds:
- --
- REVOKE ALL ON kinds FROM manuel;
+-- revoke all privileges from user manuel on view kinds:
+--
+REVOKE ALL ON kinds FROM manuel;
</ProgramListing>
</REFSECT1>
Compatibility
</TITLE>
<PARA>
-</PARA>
<REFSECT2 ID="R2-SQL-REVOKE-4">
<REFSECT2INFO>
SQL92
</TITLE>
<PARA>
- The SQL92 syntax for REVOKE has additional capabilities for rescinding
+ The SQL92 syntax for <command>REVOKE</command>
+ has additional capabilities for rescinding
privileges, including those on individual columns in tables:
<variablelist>
this privilege it fails if he/she specify the RESTRICT
keyword.
</REFENTRY>
-
-<!--
-<REPLACEABLE CLASS="PARAMETER">
-</REPLACEABLE>
-<ReturnValue></ReturnValue>
-<PARA>
-</PARA>
-<VARIABLELIST>
-<VARLISTENTRY>
-<TERM>•
-</TERM>
-<LISTITEM>
-<PARA>
-</PARA>
-</LISTITEM>
-</VARLISTENTRY>
-</VARIABLELIST>
-<PARA>
-</PARA>
--->
</REFPURPOSE>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
ROLLBACK [ WORK ]
<REFSECT2 ID="R2-SQL-ROLLBACK-1">
<REFSECT2INFO>
-<DATE>1998-09-01</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
<REFSECT2 ID="R2-SQL-ROLLBACK-2">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
<REFSECT1 ID="R1-SQL-ROLLBACK-1">
<REFSECT1INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
- ROLLBACK rolls back the current transaction and causes
+ <command>ROLLBACK</command> rolls back the current transaction and causes
all the updates made by the transaction to be discarded.
<REFSECT2 ID="R2-SQL-ROLLBACK-3">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
The keyword WORK is noise and can be omitted.
<para>
-Use the COMMIT statement to successfully terminate a transaction.
+Use the <command>COMMIT</command> statement to successfully
+ terminate a transaction.
</REFSECT1>
</TITLE>
<PARA>
<ProgramListing>
- --To abort all changes:
- --
- ROLLBACK WORK;
+--To abort all changes:
+--
+ROLLBACK WORK;
</ProgramListing>
</REFSECT1>
<REFSECT2 ID="R2-SQL-ROLLBACK-4">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
<PARA>
Full compatibility.
</REFENTRY>
-
-<!--
-<REPLACEABLE CLASS="PARAMETER">
-</REPLACEABLE>
-<ReturnValue></ReturnValue>
-<PARA>
-</PARA>
-<VARIABLELIST>
-<VARLISTENTRY>
-<TERM>•
-</TERM>
-<LISTITEM>
-<PARA>
-</PARA>
-</LISTITEM>
-</VARLISTENTRY>
-</VARIABLELIST>
-<PARA>
-</PARA>
--->
</refpurpose></refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsynopsisdivinfo>
<synopsis>
SELECT [ALL|DISTINCT]
- <replaceable class="PARAMETER">expression</replaceable> [AS <replaceable class="PARAMETER">name</replaceable>] [, ...]
- [INTO [TABLE] <replaceable class="PARAMETER">intable</replaceable>]
- [FROM <replaceable class="PARAMETER">table</replaceable> [<replaceable class="PARAMETER">alias</replaceable>] [, ...] ]
- [WHERE <replaceable class="PARAMETER">condition</replaceable>]
- [GROUP BY <replaceable class="PARAMETER">column</replaceable> [, ...] ]
- [HAVING <replaceable class="PARAMETER">condition</replaceable> [, ...] ]
- [UNION [ALL] <replaceable class="PARAMETER">select</replaceable>]
- [ORDER BY <replaceable class="PARAMETER">column</replaceable> [ASC | DESC] [, ...] ]
+ <replaceable class="PARAMETER">expression</replaceable> [ AS <replaceable class="PARAMETER">name</replaceable> ] [, ...]
+ [ INTO [TABLE] <replaceable class="PARAMETER">new_table</replaceable> ]
+ [ FROM <replaceable class="PARAMETER">table</replaceable> [<replaceable class="PARAMETER">alias</replaceable> ] [, ...] ]
+ [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
+ [ GROUP BY <replaceable class="PARAMETER">column</replaceable> [, ...] ]
+ [ HAVING <replaceable class="PARAMETER">condition</replaceable> [, ...] ]
+ [ UNION [ALL] <replaceable class="PARAMETER">select</replaceable> ]
+ [ ORDER BY <replaceable class="PARAMETER">column</replaceable> [ ASC | DESC ] [, ...] ]
</synopsis>
<refsect2 id="R2-SQL-SELECT-1">
<refsect2info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect2info>
<title>
Inputs
<varlistentry>
<term>
- <replaceable class="PARAMETER">intable</replaceable>
+ <replaceable class="PARAMETER">new_table</replaceable>
</term>
<listitem>
<para>
If the INTO TABLE clause is specified, the result of the
query will be stored in another table with the indicated
name.
- If <replaceable class="PARAMETER">intable</replaceable> does
+ If <replaceable class="PARAMETER">new_table</replaceable> does
not exist, it will be created automatically.
-
+ Refer to <command>SELECT INTO</command> for more information.
<note>
<para>
The <command>CREATE TABLE AS</command> statement will also
<refsect2 id="R2-SQL-SELECT-2">
<refsect2info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect2info>
<title>
Outputs
</title>
+<para>
+
<variablelist>
<varlistentry>
<term>
<varlistentry>
<term>
- <returnvalue>count</returnvalue>
+ <replaceable>status</replaceable>
+ </term>
+ <listitem>
+ <para>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <returnvalue><replaceable>count</replaceable></returnvalue>
</term>
<listitem>
<para>
</listitem>
</varlistentry>
</variablelist>
+ </variablelist>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-SQL-SELECT-1">
<refsect1info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect1info>
<title>
Description
</title>
<para>
- SELECT will get all rows which satisfy the WHERE condition
+ <command>SELECT</command> will get all rows which satisfy the
+ WHERE condition
or all rows of a table if WHERE is omitted.</para>
<para>
<para>
You must have SELECT privilege to a table to read its values
- (See GRANT/REVOKE statements).</para>
+ (See <command>GRANT</command>/<command>REVOKE</command> statements).
+</para>
<refsect2 id="R2-SQL-WHERE-2">
<refsect2info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect2info>
<title>
- WHERE clause
+ WHERE Clause
</title>
<para>
The optional WHERE condition has the general form:
<synopsis>
-WHERE <replaceable class="PARAMETER">expr</replaceable> <replaceable class="PARAMETER">cond_op</replaceable> <replaceable class="PARAMETER">expr</replaceable> [<replaceable class="PARAMETER">log_op</replaceable> ...]
+WHERE <replaceable class="PARAMETER">expr</replaceable> <replaceable class="PARAMETER">cond_op</replaceable> <replaceable class="PARAMETER">expr</replaceable> [ <replaceable class="PARAMETER">log_op</replaceable> ... ]
</synopsis>
where <replaceable class="PARAMETER">cond_op</replaceable> can be
<refsect2 id="R2-SQL-GROUPBY-2">
<refsect2info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect2info>
<title>
- GROUP BY clause
+ GROUP BY Clause
</title>
<para>
GROUP BY specifies a grouped table derived by the application
of the this clause:
<synopsis>
- GROUP BY <replaceable class="PARAMETER">column</replaceable> [, ...]
+GROUP BY <replaceable class="PARAMETER">column</replaceable> [, ...]
</synopsis></para></refsect2>
<refsect2 id="R2-SQL-HAVING-2">
<refsect2info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect2info>
<title>
- HAVING clause
+ HAVING Clause
</title>
<para>
The optional HAVING condition has the general form:
that do not meet the <replaceable class="PARAMETER">cond_expr</replaceable>.</para>
<para>
- Each column referenced in <replaceable class="PARAMETER">cond_expr</replaceable> shall unambiguously
+ Each column referenced in
+<replaceable class="PARAMETER">cond_expr</replaceable> shall unambiguously
reference a grouping column.
</para>
</refsect2>
<refsect2 id="R2-SQL-ORDERBYCLAUSE-2">
<refsect2info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect2info>
<title>
- ORDER BY clause
+ ORDER BY Clause
</title>
<para>
<synopsis>
-ORDER BY <replaceable class="PARAMETER">column</replaceable> [ASC | DESC] [, ...]
+ORDER BY <replaceable class="PARAMETER">column</replaceable> [ ASC | DESC ] [, ...]
</synopsis></para>
<para>
The ordinal numbers refers to the ordinal (left-to-right) position
of the column. This feature makes it possible to define an ordering
on the basis of a column that does not have a proper name.
- This is never absolutely necessary because it is always possible assign a name
+ This is never absolutely necessary because it is always possible
+ assign a name
to a calculated column using the AS clause, e.g.:
<programlisting>
- SELECT title, date_prod + 1 AS newlen FROM films ORDER BY newlen;
+SELECT title, date_prod + 1 AS newlen FROM films ORDER BY newlen;
</programlisting></para>
<para>
The columns in the ORDER BY must appear in the SELECT clause.
Thus the following statement is illegal:
<programlisting>
- SELECT name FROM distributors ORDER BY code;
+SELECT name FROM distributors ORDER BY code;
</programlisting></para>
<para>
<refsect2 id="R2-SQL-UNION-2">
<refsect2info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect2info>
<title>
- UNION clause
+ UNION Clause
</title>
<para>
<synopsis>
-<replaceable class="PARAMETER">table_query</replaceable> UNION [ALL] <replaceable class="PARAMETER">table_query</replaceable>
- [ORDER BY <replaceable class="PARAMETER">column</replaceable> [ASC | DESC] [, ...] ]
+<replaceable class="PARAMETER">table_query</replaceable> UNION [ ALL ] <replaceable class="PARAMETER">table_query</replaceable>
+ [ ORDER BY <replaceable class="PARAMETER">column</replaceable> [ ASC | DESC ] [, ...] ]
</synopsis>
where
unless the ALL clause is specified.</para>
<para>
- Multiple UNION operators in the same SELECT statement are evaluated left to right.
- Note that the ALL keyword is not global in nature, being applied only for the current pair of
- table results.</para>
+ Multiple UNION operators in the same SELECT statement are
+evaluated left to right.
+ Note that the ALL keyword is not global in nature, being
+applied only for the current pair of table results.</para>
</refsect2></refsect1>
<literal>distributors</literal>:
</para>
<programlisting>
- SELECT f.title, f.did, d.name, f.date_prod, f.kind
- FROM distributors d, films f
- WHERE f.did = d.did
+SELECT f.title, f.did, d.name, f.date_prod, f.kind
+ FROM distributors d, films f
+ WHERE f.did = d.did
title |did|name | date_prod|kind
-------------------------+---+----------------+----------+----------
the reults by <literal>kind</literal>:
</para>
<programlisting>
- SELECT kind, SUM(len) AS total FROM films GROUP BY kind;
+SELECT kind, SUM(len) AS total FROM films GROUP BY kind;
kind |total
----------+------
that are less than 5 hours:
</para>
<programlisting>
- SELECT kind, SUM(len) AS total
- FROM films
- GROUP BY kind
- HAVING SUM(len) < INTERVAL '5 hour';
+SELECT kind, SUM(len) AS total
+ FROM films
+ GROUP BY kind
+ HAVING SUM(len) < INTERVAL '5 hour';
kind |total
----------+------
(<literal>name</literal>):
</para>
<programlisting>
- SELECT * FROM distributors ORDER BY name;
- SELECT * FROM distributors ORDER BY 2;
+SELECT * FROM distributors ORDER BY name;
+SELECT * FROM distributors ORDER BY 2;
did|name
---+----------------
-- 112|Warner Bros. 3|Walter Matthau
-- ... ...
- SELECT distributors.name
+SELECT distributors.name
FROM distributors
WHERE distributors.name LIKE 'W%'
- UNION
- SELECT actors.name
- FROM actors
- WHERE actors.name LIKE 'W%'
+UNION
+SELECT actors.name
+ FROM actors
+ WHERE actors.name LIKE 'W%'
name
--------------
<refsect2 id="R2-SQL-SELECT-4">
<refsect2info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect2info>
<title>
<acronym>SQL92</acronym>
<date>1998-04-15</date>
</refsect3info>
<title>
- SELECT clause
+ SELECT Clause
</title>
<para>
In the <acronym>SQL92</acronym> standard, the optional keyword "AS"
<refsect3 id="R3-SQL-UNION-1">
<refsect3info>
- <date>1998-09-06</date>
+ <date>1998-09-24</date>
</refsect3info>
<title>
- UNION clause
+ UNION Clause
</title>
<para>
The <acronym>SQL92</acronym> syntax for UNION allows an
</refsect1>
</refentry>
+<refentry id="SQL-SELECTINTO">
+ <refmeta>
+ <refentrytitle>
+ SELECT
+ </refentrytitle>
+ <refmiscinfo>SQL - Language Statements</refmiscinfo>
+ </refmeta>
+ <refnamediv>
+ <refname>
+ SELECT INTO
+ </refname>
+ <refpurpose>
+ Create a new table from an existing table or view
+ </refpurpose></refnamediv>
+ <refsynopsisdiv>
+ <refsynopsisdivinfo>
+ <date>1998-09-22</date>
+ </refsynopsisdivinfo>
+ <synopsis>
+SELECT [ ALL | DISTINCT ] <replaceable class="PARAMETER">expression</replaceable> [ AS <replaceable class="PARAMETER">name</replaceable> ] [, ...]
+ INTO [ TABLE ] <replaceable class="PARAMETER">new_table</replaceable> ]
+ [ FROM <replaceable class="PARAMETER">table</replaceable> [<replaceable class="PARAMETER">alias</replaceable>] [, ...] ]
+ [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
+ [ GROUP BY <replaceable class="PARAMETER">column</replaceable> [, ...] ]
+ [ HAVING <replaceable class="PARAMETER">condition</replaceable> [, ...] ]
+ [ UNION [ ALL ] <replaceable class="PARAMETER">select</replaceable>]
+ [ ORDER BY <replaceable class="PARAMETER">column</replaceable> [ ASC | DESC ] [, ...] ]
+ </synopsis>
+
+ <refsect2 id="R2-SQL-SELECTINTO-1">
+ <refsect2info>
+ <date>1998-09-22</date>
+ </refsect2info>
+ <title>
+ Inputs
+ </title>
+ <para>
+All input fields are described in detail for SELECT.
+
+ <refsect2 id="R2-SQL-SELECTINTO-2">
+ <refsect2info>
+ <date>1998-09-22</date>
+ </refsect2info>
+ <title>
+ Outputs
+ </title>
+ <para>
+All output fields are described in detail for SELECT.
+
+ <refsect1 id="R1-SQL-SELECTINTO-1">
+ <refsect1info>
+ <date>1998-09-22</date>
+ </refsect1info>
+ <title>
+ Description
+ </title>
+ <para>
+SELECT INTO creates a new table from the results of a query. Typically, this
+query draws data from an existing table, but any SQL query is allowed.
+<note>
+<para>
+CREATE TABLE AS is functionally equivalent to the SELECT INTO command.
+</note>
+
+ </refsect1>
+</refentry>
+
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
</REFPURPOSE>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
<REPLACEABLE CLASS="PARAMETER">
<REFSECT2 ID="R2-SQL-SET-1">
<REFSECT2INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
</TITLE>
<PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
</varlistentry>
</variablelist>
-There are also several internal or optimization parameters which can be specified
+There are also several internal or optimization
+ parameters which can be specified
by the <command>SET</command> command:
<variablelist>
for statements with 8 or more tables.
<varlistentry>
<term>
-On=#
+On=<replaceable class="parameter">#</replaceable>
</term>
<listitem>
<para>
-enables the genetic optimizer algorithm
- for statements with # or more tables.
+Takes an integer argument to enable the genetic optimizer algorithm
+ for statements with <replaceable class="parameter">#</replaceable>
+ or more tables in the query.
<varlistentry>
<term>
Off
<REFSECT2 ID="R2-SQL-SET-2">
<REFSECT2INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
+
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<replaceable>status</replaceable>
+</TERM>
+<LISTITEM>
+<PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
- SET VARIABLE
+<returnvalue>SET VARIABLE</returnvalue>
</TERM>
<LISTITEM>
<PARA>
<VARLISTENTRY>
<TERM>
- WARN: Bad value for <replaceable class="parameter">variable</replaceable> (<replaceable class="parameter">value</replaceable>)
+<returnvalue>WARN: Bad value for <replaceable class="parameter">variable</replaceable> (<replaceable class="parameter">value</replaceable>)</returnvalue>
</TERM>
<LISTITEM>
<PARA>
- If fails to set variable.
+ If the command fails to set variable.
</VARLISTENTRY>
</VARIABLELIST>
+</VARIABLELIST>
</REFSECT2>
</REFSYNOPSISDIV>
<REFSECT1 ID="R1-SQL-SET-1">
<REFSECT1INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
-SET will modify configuration parameters for variable during
+<command>SET</command> will modify configuration parameters for variable during
a session.
<para>
- Current values can be obtained using SHOW statement, and values
- can be restored to the defaults using RESET statement.
+ Current values can be obtained using <command>SHOW</command>, and values
+ can be restored to the defaults using <command>RESET</command>.
Parameters and values are case-insensitive. Note that the value
field is always specified as a string, so is enclosed in
single-quotes.
<para>
- SET TIME ZONE changes the session's default time zone offset.
+ <command>SET TIME ZONE</command> changes the session's
+ default time zone offset.
A SQL-session always begins with an initial default time zone
offset.
- The SET TIME ZONE statement is used to change the default
+ The <command>SET TIME ZONE</command> statement is used to change the default
time zone offset for the current SQL session.
<REFSECT2 ID="R2-SQL-SET-3">
<REFSECT2INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
statement is a <productname>Postgres</productname> language extension.
<para>
- Refer to SHOW/RESET statements to show/reset variable values.
+ Refer to <command>SHOW</command> and <command>RESET</command> to
+display or reset the current values.
</REFSECT2>
</REFSECT1>
<PARA>
</PARA>
<ProgramListing>
- --Set the style of date to ISO:
- --
- SET DATESTYLE TO 'ISO';
+--Set the style of date to ISO:
+--
+SET DATESTYLE TO 'ISO';
</programlisting>
<programlisting>
- --Set GEQO to default:
- --
- SET GEQO = DEFAULT;
+--Set GEQO to default:
+--
+SET GEQO = DEFAULT;
</programlisting>
<programlisting>
- --Turn on right-hand evaluation of plans:
- --
- SET R_PLANS TO 'on';
+--Turn on right-hand evaluation of plans:
+--
+SET R_PLANS TO 'on';
</programlisting>
<programlisting>
- --set the timezone for Berkeley, California:
- SET TIME ZONE 'PST8PDT';
+--set the timezone for Berkeley, California:
+SET TIME ZONE 'PST8PDT';
- SELECT CURRENT_TIMESTAMP AS today;
+SELECT CURRENT_TIMESTAMP AS today;
today
----------------------
1998-03-31 07:41:21-08
</programlisting>
<programlisting>
- --set the timezone for Italy:
- SET TIME ZONE 'Europe/Rome';
+--set the timezone for Italy:
+SET TIME ZONE 'Europe/Rome';
- SELECT CURRENT_TIMESTAMP AS today;
+SELECT CURRENT_TIMESTAMP AS today;
today
----------------------
<REFSECT2 ID="R2-SQL-SET-4">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
<PARA>
There is no
<command>SET <replaceable class="parameter">variable</replaceable></command>
- in SQL92.
+ in <acronym>SQL92</acronym>.
- The SQL92 syntax for SET TIME ZONE is slightly different,
+ The <acronym>SQL92</acronym> syntax for <command>SET TIME ZONE</command>
+ is slightly different,
allowing only a single integer value for time zone specification:
<programlisting>
</programlisting>
</REFENTRY>
-
-<!--
-<REPLACEABLE CLASS="PARAMETER">
-</REPLACEABLE>
-<ReturnValue></ReturnValue>
-<PARA>
-</PARA>
-<VARIABLELIST>
-<VARLISTENTRY>
-<TERM>•
-</TERM>
-<LISTITEM>
-<PARA>
-</PARA>
-</LISTITEM>
-</VARLISTENTRY>
-</VARIABLELIST>
-<PARA>
-</PARA>
--->
</REFPURPOSE>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
SHOW <REPLACEABLE CLASS="PARAMETER">variable</REPLACEABLE>
<REFSECT2 ID="R2-SQL-SHOW-1">
<REFSECT2INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
</TITLE>
<PARA>
-</PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
</TERM>
<LISTITEM>
<PARA>
- Refer to the SET statement for more information on available
+ Refer to <command>SET</command> for more information on available
variables.
</VARLISTENTRY>
</VARIABLELIST>
<REFSECT2 ID="R2-SQL-SHOW-2">
<REFSECT2INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
</TITLE>
<PARA>
-</PARA>
+
+<VARIABLELIST>
+<VARLISTENTRY>
+<TERM>
+<REPLACEABLE>status</REPLACEABLE>
+</TERM>
+<LISTITEM>
+<PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
-NOTICE: <REPLACEABLE CLASS="PARAMETER">variable</REPLACEABLE> is <ReturnValue>value</ReturnValue>
+<returnvalue>NOTICE: <REPLACEABLE CLASS="PARAMETER">variable</REPLACEABLE> is <replaceable>value</replaceable></ReturnValue>
SHOW VARIABLE
</TERM>
<LISTITEM>
<PARA>
Message returned if successfully.
</listitem>
+
<VARLISTENTRY>
<TERM>
-NOTICE: Unrecognized variable <ReturnValue>value</ReturnValue>
+<returnvalue>NOTICE: Unrecognized variable <replaceable>value</replaceable></ReturnValue>
+</TERM>
<LISTITEM>
<PARA>
Message returned if <ReturnValue>value</ReturnValue> does not exist.
</PARA>
</LISTITEM>
</VARLISTENTRY>
+
+<VARLISTENTRY>
+<TERM>
+NOTICE: Time zone is unknown
+SHOW VARIABLE
+</TERM>
+<LISTITEM>
+<PARA>
+ If the TZ environment variable is not set.
+
</VARIABLELIST>
+</VARIABLELIST>
+
</REFSECT2>
</REFSYNOPSISDIV>
<REFSECT1 ID="R1-SQL-SHOW-1">
<REFSECT1INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
</TITLE>
<PARA>
- SHOW will display the current configuration parameters for
+ <command>SHOW</command> will display the current
+ configuration parameters for
variable during a session.
<para>
- The session can be configured using SET statement, and values
- can be restored to the defaults using RESET statement.
+ The session can be configured using <command>SET</command> statement,
+ and values
+ can be restored to the defaults using <command>RESET</command> statement.
Parameters and values are case-insensitive.
<REFSECT2 ID="R2-SQL-SHOW-3">
<REFSECT2INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Notes
</TITLE>
<PARA>
- The SHOW statement is a <productname>Postgres</productname>
+ The <command>SHOW</command> is a <productname>Postgres</productname>
language extension.
<para>
- Refer to the SET/RESET statements to set/reset variable values.
- See also the SET TIME ZONE statement.
+ Refer to <command>SET</command>/<command>RESET</command>
+ to set/reset variable values.
+ See also <command>SET TIME ZONE</command>.
-<para>
- If the TZ environment variable is not set the SHOW TIME ZONE statement
- gives the message: Time zone is unknown
</REFSECT2>
</REFSECT1>
</TITLE>
<PARA>
<ProgramListing>
- -- show DateStyle;
- SHOW DateStyle;
- NOTICE:DateStyle is Postgres with US (NonEuropean) conventions
+-- show DateStyle;
+SHOW DateStyle;
+NOTICE:DateStyle is Postgres with US (NonEuropean) conventions
- -- show Geqo;
- SHOW GEQO;
- NOTICE:GEQO is ON
+-- show Geqo;
+SHOW GEQO;
+NOTICE:GEQO is ON
</ProgramListing>
</REFSECT1>
<REFSECT2 ID="R2-SQL-SHOW-4">
<REFSECT2INFO>
-<DATE>1998-08-31</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
SQL92
</TITLE>
<PARA>
- There is no SET statement defined in <acronym>SQL92</acronym>.
+ There is no <command>SET</command> defined in <acronym>SQL92</acronym>.
</refsect2>
</refsect1>
</REFENTRY>
<REFSYNOPSISDIV>
<REFSYNOPSISDIVINFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSYNOPSISDIVINFO>
<SYNOPSIS>
UPDATE <REPLACEABLE CLASS="PARAMETER">table</replaceable> SET <REPLACEABLE CLASS="PARAMETER">column</replaceable> = <REPLACEABLE CLASS="PARAMETER">expression</replaceable> [, ...]
- [FROM <REPLACEABLE CLASS="PARAMETER">fromlist</REPLACEABLE>]
- [WHERE <REPLACEABLE CLASS="PARAMETER">condition</REPLACEABLE>]
+ [ FROM <REPLACEABLE CLASS="PARAMETER">fromlist</REPLACEABLE> ]
+ [ WHERE <REPLACEABLE CLASS="PARAMETER">condition</REPLACEABLE> ]
</SYNOPSIS>
<REFSECT2 ID="R2-SQL-UPDATE-1">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Inputs
</TITLE>
<PARA>
-</PARA>
+
<VARIABLELIST>
<VARLISTENTRY>
<TERM>
<REFSECT2 ID="R2-SQL-UPDATE-2">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
Outputs
<REFSECT1 ID="R1-SQL-UPDATE-1">
<REFSECT1INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT1INFO>
<TITLE>
Description
<REFSECT2 ID="R2-SQL-UPDATE-4">
<REFSECT2INFO>
-<DATE>1998-04-15</DATE>
+<DATE>1998-09-24</DATE>
</REFSECT2INFO>
<TITLE>
SQL92