1999-05-12 09:32:47 +02:00
|
|
|
<chapter>
|
|
|
|
<title>SQL Syntax</title>
|
|
|
|
|
|
|
|
<abstract>
|
|
|
|
<para>
|
|
|
|
<acronym>SQL</acronym> manipulates sets of data. The language is
|
|
|
|
composed of various <firstterm>key words</firstterm>. Arithmetic
|
|
|
|
and procedural expressions are allowed. We will cover these topics
|
|
|
|
in this chapter; subsequent chapters will include details on data
|
|
|
|
types, functions, and operators.
|
|
|
|
</para>
|
|
|
|
</abstract>
|
|
|
|
|
|
|
|
<sect1>
|
|
|
|
<title>Key Words</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<acronym>SQL92</acronym> defines <firstterm>key words</firstterm>
|
|
|
|
for the language
|
|
|
|
which have specific meaning. Some key words are
|
|
|
|
<firstterm>reserved</firstterm>, which indicates that they are
|
|
|
|
restricted to appear in only certain contexts. Other key words are
|
|
|
|
<firstterm>not restricted</firstterm>, which indicates that in certain
|
|
|
|
contexts they
|
|
|
|
have a specific meaning but are not otherwise constrained.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<productname>Postgres</productname> implements an extended subset of the
|
|
|
|
<acronym>SQL92</acronym> and <acronym>SQL3</acronym> languages. Some language
|
|
|
|
elements are not as restricted in this implementation as is
|
|
|
|
called for in the language standards, in part due
|
|
|
|
to the extensibility features of <productname>Postgres</productname>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Information on <acronym>SQL92</acronym> and <acronym>SQL3</acronym> key words
|
|
|
|
is derived from <xref linkend="DATE97" endterm="DATE97">.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Reserved Key Words</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<acronym>SQL92</acronym> and <acronym>SQL3</acronym> have
|
|
|
|
<firstterm>reserved key words</firstterm> which are not allowed
|
|
|
|
as identifiers and not allowed in any usage other than as fundamental
|
|
|
|
tokens in <acronym>SQL</acronym> statements.
|
|
|
|
<productname>Postgres</productname> has additional key words
|
|
|
|
which have similar restrictions. In particular, these key words
|
|
|
|
are not allowed as column or table names, though in some cases
|
|
|
|
they are allowed to be column labels (i.e. in AS clauses).
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
Any string can be specified as an identifier if surrounded by
|
|
|
|
double quotes (<quote>like this!</quote>). Some care is required since
|
|
|
|
such an identifier will be case sensitive
|
|
|
|
and will retain embedded whitespace other special characters.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following are <productname>Postgres</productname>
|
|
|
|
reserved words which are neither <acronym>SQL92</acronym>
|
|
|
|
nor <acronym>SQL3</acronym> reserved words. These are allowed
|
|
|
|
to be present as column labels, but not as identifiers:
|
|
|
|
|
|
|
|
<programlisting>
|
1998-09-30 07:41:54 +02:00
|
|
|
ABORT ANALYZE
|
|
|
|
BINARY
|
|
|
|
CLUSTER CONSTRAINT COPY
|
|
|
|
DO
|
|
|
|
EXPLAIN EXTEND
|
|
|
|
LISTEN LOAD LOCK
|
|
|
|
MOVE
|
|
|
|
NEW NONE NOTIFY
|
|
|
|
RESET
|
|
|
|
SETOF SHOW
|
|
|
|
UNLISTEN UNTIL
|
|
|
|
VACUUM VERBOSE
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
|
|
|
The following are <productname>Postgres</productname>
|
|
|
|
reserved words which are also <acronym>SQL92</acronym>
|
|
|
|
or <acronym>SQL3</acronym> reserved words, and which
|
|
|
|
are allowed to be present as column labels, but not as identifiers:
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<programlisting>
|
1998-12-18 17:13:45 +01:00
|
|
|
CASE COALESCE CROSS CURRENT
|
|
|
|
ELSE END
|
1998-09-30 07:41:54 +02:00
|
|
|
FALSE FOREIGN
|
1999-05-12 09:32:47 +02:00
|
|
|
GLOBAL GROUP
|
|
|
|
LOCAL
|
1998-12-18 17:13:45 +01:00
|
|
|
NULLIF
|
1998-09-30 07:41:54 +02:00
|
|
|
ORDER
|
|
|
|
POSITION PRECISION
|
1998-12-18 17:13:45 +01:00
|
|
|
TABLE THEN TRANSACTION TRUE
|
|
|
|
WHEN
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
The following are <productname>Postgres</productname>
|
|
|
|
reserved words which are also <acronym>SQL92</acronym>
|
|
|
|
or <acronym>SQL3</acronym> reserved words:
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<programlisting>
|
1998-09-30 07:41:54 +02:00
|
|
|
ADD ALL ALTER AND ANY AS ASC
|
|
|
|
BEGIN BETWEEN BOTH BY
|
1998-12-18 17:13:45 +01:00
|
|
|
CASCADE CAST CHAR CHARACTER CHECK CLOSE
|
|
|
|
COLLATE COLUMN COMMIT CONSTRAINT
|
|
|
|
CREATE CURRENT_DATE CURRENT_TIME
|
|
|
|
CURRENT_TIMESTAMP CURRENT_USER CURSOR
|
1998-09-30 07:41:54 +02:00
|
|
|
DECIMAL DECLARE DEFAULT DELETE DESC DISTINCT DROP
|
1998-12-18 17:13:45 +01:00
|
|
|
EXECUTE EXISTS EXTRACT
|
1998-09-30 07:41:54 +02:00
|
|
|
FETCH FLOAT FOR FROM FULL
|
|
|
|
GRANT
|
|
|
|
HAVING
|
|
|
|
IN INNER INSERT INTERVAL INTO IS
|
|
|
|
JOIN
|
|
|
|
LEADING LEFT LIKE LOCAL
|
|
|
|
NAMES NATIONAL NATURAL NCHAR NO NOT NULL NUMERIC
|
|
|
|
ON OR OUTER
|
|
|
|
PARTIAL PRIMARY PRIVILEGES PROCEDURE PUBLIC
|
|
|
|
REFERENCES REVOKE RIGHT ROLLBACK
|
|
|
|
SELECT SET SUBSTRING
|
1998-10-14 18:28:53 +02:00
|
|
|
TO TRAILING TRIM
|
1998-09-30 07:41:54 +02:00
|
|
|
UNION UNIQUE UPDATE USER USING
|
|
|
|
VALUES VARCHAR VARYING VIEW
|
|
|
|
WHERE WITH WORK
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
|
|
|
The following are <acronym>SQL92</acronym> reserved key words which
|
|
|
|
are not <productname>Postgres</productname> reserved key words, but which
|
|
|
|
if used as function names are always translated into the function
|
|
|
|
<function>length</function>:
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<programlisting>
|
1998-09-30 07:41:54 +02:00
|
|
|
CHAR_LENGTH CHARACTER_LENGTH
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
|
|
|
The following are <acronym>SQL92</acronym> or <acronym>SQL3</acronym>
|
|
|
|
reserved key words which
|
|
|
|
are not <productname>Postgres</productname> reserved key words, but
|
|
|
|
if used as type names are always translated into an alternate, native type:
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<programlisting>
|
1998-09-30 07:41:54 +02:00
|
|
|
BOOLEAN DOUBLE FLOAT INT INTEGER INTERVAL REAL SMALLINT
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following are either <acronym>SQL92</acronym>
|
|
|
|
or <acronym>SQL3</acronym> reserved key words
|
|
|
|
which are not key words in <productname>Postgres</productname>.
|
|
|
|
These have no proscribed usage in <productname>Postgres</productname>
|
|
|
|
at the time of writing (v6.5) but may become reserved key words in the
|
|
|
|
future:
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
Some of these key words represent functions in <acronym>SQL92</acronym>.
|
|
|
|
These functions are defined in <productname>Postgres</productname>,
|
|
|
|
but the parser does not consider the names to be key words and they are allowed
|
|
|
|
in other contexts.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<programlisting>
|
1998-09-30 07:41:54 +02:00
|
|
|
ALLOCATE ARE ASSERTION AT AUTHORIZATION AVG
|
|
|
|
BIT BIT_LENGTH
|
1998-12-18 17:13:45 +01:00
|
|
|
CASCADED CATALOG COLLATION CONNECT CONNECTION
|
|
|
|
CONSTRAINTS CONTINUE CONVERT CORRESPONDING COUNT
|
1998-09-30 07:41:54 +02:00
|
|
|
DATE DEALLOCATE DEC DESCRIBE DESCRIPTOR DIAGNOSTICS DISCONNECT DOMAIN
|
1998-12-18 17:13:45 +01:00
|
|
|
END-EXEC ESCAPE EXCEPT EXCEPTION EXEC EXTERNAL
|
1998-09-30 07:41:54 +02:00
|
|
|
FIRST FOUND
|
1999-05-12 09:32:47 +02:00
|
|
|
GET GO GOTO
|
1998-09-30 07:41:54 +02:00
|
|
|
IDENTITY IMMEDIATE INDICATOR INITIALLY INPUT INTERSECT ISOLATION
|
|
|
|
LAST LEVEL LOWER
|
|
|
|
MAX MIN MODULE
|
|
|
|
OCTET_LENGTH OPEN OUTPUT OVERLAPS
|
|
|
|
PREPARE PRESERVE
|
|
|
|
RESTRICT ROWS
|
|
|
|
SCHEMA SECTION SESSION SESSION_USER SIZE SOME
|
1998-12-18 17:13:45 +01:00
|
|
|
SQL SQLCODE SQLERROR SQLSTATE SUM SYSTEM_USER
|
|
|
|
TEMPORARY TRANSLATE TRANSLATION
|
1998-09-30 07:41:54 +02:00
|
|
|
UNKNOWN UPPER USAGE
|
|
|
|
VALUE
|
1998-12-18 17:13:45 +01:00
|
|
|
WHENEVER WRITE
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Non-reserved Keywords</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<acronym>SQL92</acronym> and <acronym>SQL3</acronym> have
|
|
|
|
<firstterm>non-reserved keywords</firstterm> which have
|
|
|
|
a proscribed meaning in the language but which are also allowed
|
|
|
|
as identifiers.
|
|
|
|
<productname>Postgres</productname> has additional keywords
|
|
|
|
which allow similar unrestricted usage.
|
|
|
|
In particular, these keywords
|
|
|
|
are allowed as column or table names.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following are <productname>Postgres</productname>
|
|
|
|
non-reserved key words which are neither <acronym>SQL92</acronym>
|
|
|
|
nor <acronym>SQL3</acronym> non-reserved key words:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
ACCESS AFTER AGGREGATE
|
1998-09-30 07:41:54 +02:00
|
|
|
BACKWARD BEFORE
|
|
|
|
CACHE CREATEDB CREATEUSER CYCLE
|
|
|
|
DATABASE DELIMITERS
|
1999-05-12 09:32:47 +02:00
|
|
|
EACH ENCODING EXCLUSIVE
|
1998-09-30 07:41:54 +02:00
|
|
|
FORWARD FUNCTION
|
|
|
|
HANDLER
|
|
|
|
INCREMENT INDEX INHERITS INSENSITIVE INSTEAD ISNULL
|
|
|
|
LANCOMPILER LOCATION
|
1999-05-12 09:32:47 +02:00
|
|
|
MAXVALUE MINVALUE MODE
|
1998-09-30 07:41:54 +02:00
|
|
|
NOCREATEDB NOCREATEUSER NOTHING NOTNULL
|
|
|
|
OIDS OPERATOR
|
|
|
|
PASSWORD PROCEDURAL
|
|
|
|
RECIPE RENAME RETURNS ROW RULE
|
1999-05-12 09:32:47 +02:00
|
|
|
SEQUENCE SERIAL SHARE START STATEMENT STDIN STDOUT
|
1998-09-30 07:41:54 +02:00
|
|
|
TRUSTED
|
|
|
|
VALID VERSION
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
|
|
|
The following are <productname>Postgres</productname>
|
|
|
|
non-reserved key words which are <acronym>SQL92</acronym>
|
|
|
|
or <acronym>SQL3</acronym> reserved key words:
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<programlisting>
|
1998-09-30 07:41:54 +02:00
|
|
|
ABSOLUTE ACTION
|
|
|
|
DAY
|
|
|
|
HOUR
|
|
|
|
INSENSITIVE
|
|
|
|
KEY
|
|
|
|
LANGUAGE
|
|
|
|
MATCH MINUTE MONTH
|
|
|
|
NEXT
|
|
|
|
OF ONLY OPTION
|
|
|
|
PRIOR PRIVILEGES
|
|
|
|
READ RELATIVE
|
|
|
|
SCROLL SECOND
|
1998-10-14 18:28:53 +02:00
|
|
|
TIME TIMESTAMP TIMEZONE_HOUR TIMEZONE_MINUTE TRIGGER
|
1998-09-30 07:41:54 +02:00
|
|
|
YEAR
|
|
|
|
ZONE
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
|
|
|
The following are <productname>Postgres</productname>
|
|
|
|
non-reserved key words which are also either <acronym>SQL92</acronym>
|
|
|
|
or <acronym>SQL3</acronym> non-reserved key words:
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<programlisting>
|
|
|
|
COMMITTED SERIALIZABLE TYPE
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<para>
|
|
|
|
The following are either <acronym>SQL92</acronym>
|
|
|
|
or <acronym>SQL3</acronym> non-reserved key words which are not
|
|
|
|
key words of any kind in <productname>Postgres</productname>:
|
1998-09-30 07:41:54 +02:00
|
|
|
|
1999-05-12 09:32:47 +02:00
|
|
|
<programlisting>
|
1998-09-30 07:41:54 +02:00
|
|
|
ADA
|
|
|
|
C CATALOG_NAME CHARACTER_SET_CATALOG CHARACTER_SET_NAME
|
|
|
|
CHARACTER_SET_SCHEMA CLASS_ORIGIN COBOL COLLATION_CATALOG
|
|
|
|
COLLATION_NAME COLLATION_SCHEMA COLUMN_NAME
|
1999-05-12 09:32:47 +02:00
|
|
|
COMMAND_FUNCTION CONDITION_NUMBER
|
1998-09-30 07:41:54 +02:00
|
|
|
CONNECTION_NAME CONSTRAINT_CATALOG CONSTRAINT_NAME
|
|
|
|
CONSTRAINT_SCHEMA CURSOR_NAME
|
|
|
|
DATA DATE_TIME_INTERVAL_CODE DATE_TIME_INTERVAL_PRECISION
|
|
|
|
DYNAMIC_FUNCTION
|
|
|
|
FORTRAN
|
|
|
|
LENGTH
|
|
|
|
MESSAGE_LENGTH MESSAGE_OCTET_LENGTH MORE MUMPS
|
|
|
|
NAME NULLABLE NUMBER
|
|
|
|
PAD PASCAL PLI
|
|
|
|
REPEATABLE RETURNED_LENGTH RETURNED_OCTET_LENGTH
|
|
|
|
RETURNED_SQLSTATE ROW_COUNT
|
1999-05-12 09:32:47 +02:00
|
|
|
SCALE SCHEMA_NAME SERVER_NAME SPACE
|
1998-09-30 07:41:54 +02:00
|
|
|
SUBCLASS_ORIGIN
|
|
|
|
TABLE_NAME
|
|
|
|
UNCOMMITTED UNNAMED
|
1999-05-12 09:32:47 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
<sect1>
|
|
|
|
<title>Expressions</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<acronym>SQL92</acronym> allows <firstterm>expressions</firstterm>
|
|
|
|
to transform data in expressions. Expressions may contain operators
|
|
|
|
(see <xref linkend="operators-title" endterm="operators-title">
|
|
|
|
for more details) and functions
|
|
|
|
(<xref linkend="functions-title" endterm="functions-title"> has
|
|
|
|
more information).
|
|
|
|
|
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
</chapter>
|
1999-04-06 17:41:20 +02:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:nil
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"./reference.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:"/usr/lib/sgml/CATALOG"
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
-->
|