| 1 |
<!-- doc/src/sgml/keywords.sgml --> |
| 2 |
|
| 3 |
<appendix id="sql-keywords-appendix"> |
| 4 |
<title><acronym>SQL</acronym> Key Words</title> |
| 5 |
|
| 6 |
<indexterm zone="sql-keywords-appendix"> |
| 7 |
<primary>key word</primary> |
| 8 |
<secondary>list of</secondary> |
| 9 |
</indexterm> |
| 10 |
|
| 11 |
<para> |
| 12 |
<xref linkend="keywords-table"/> lists all tokens that are key words |
| 13 |
in the SQL standard and in <productname>PostgreSQL</productname> |
| 14 |
&version;. Background information can be found in <xref |
| 15 |
linkend="sql-syntax-identifiers"/>. |
| 16 |
(For space reasons, only the latest two versions of the SQL standard, and |
| 17 |
SQL-92 for historical comparison, are included. The differences between |
| 18 |
those and the other intermediate standard versions are small.) |
| 19 |
</para> |
| 20 |
|
| 21 |
<para> |
| 22 |
SQL distinguishes between <firstterm>reserved</firstterm> and |
| 23 |
<firstterm>non-reserved</firstterm> key words. According to the standard, |
| 24 |
reserved key words |
| 25 |
are the only real key words; they are never allowed as identifiers. |
| 26 |
Non-reserved key words only have a special meaning in particular |
| 27 |
contexts and can be used as identifiers in other contexts. Most |
| 28 |
non-reserved key words are actually the names of built-in tables |
| 29 |
and functions specified by SQL. The concept of non-reserved key |
| 30 |
words essentially only exists to declare that some predefined meaning |
| 31 |
is attached to a word in some contexts. |
| 32 |
</para> |
| 33 |
|
| 34 |
<para> |
| 35 |
In the <productname>PostgreSQL</productname> parser, life is a bit |
| 36 |
more complicated. There are several different classes of tokens |
| 37 |
ranging from those that can never be used as an identifier to those |
| 38 |
that have absolutely no special status in the parser, but are considered |
| 39 |
ordinary identifiers. (The latter is usually the case for |
| 40 |
functions specified by SQL.) Even reserved key words are not |
| 41 |
completely reserved in <productname>PostgreSQL</productname>, but |
| 42 |
can be used as column labels (for example, <literal>SELECT 55 AS |
| 43 |
CHECK</literal>, even though <token>CHECK</token> is a reserved key |
| 44 |
word). |
| 45 |
</para> |
| 46 |
|
| 47 |
<para> |
| 48 |
In <xref linkend="keywords-table"/> in the column for |
| 49 |
<productname>PostgreSQL</productname> we classify as |
| 50 |
<quote>non-reserved</quote> those key words that are explicitly |
| 51 |
known to the parser but are allowed as column or table names. |
| 52 |
Some key words that are otherwise |
| 53 |
non-reserved cannot be used as function or data type names and are |
| 54 |
marked accordingly. (Most of these words represent built-in |
| 55 |
functions or data types with special syntax. The function or type |
| 56 |
is still available but it cannot be redefined by the user.) Labeled |
| 57 |
<quote>reserved</quote> are those tokens that are not allowed as |
| 58 |
column or table names. Some reserved key words are |
| 59 |
allowable as names for functions or data types; this is also shown in the |
| 60 |
table. If not so marked, a reserved key word is only allowed as a |
| 61 |
column label. |
| 62 |
A blank entry in this column means that the word is treated as an |
| 63 |
ordinary identifier by <productname>PostgreSQL</productname>. |
| 64 |
</para> |
| 65 |
|
| 66 |
<para> |
| 67 |
Furthermore, while most key words can be used as <quote>bare</quote> |
| 68 |
column labels without writing <literal>AS</literal> before them (as |
| 69 |
described in <xref linkend="queries-column-labels"/>), there are a few |
| 70 |
that require a leading <literal>AS</literal> to avoid ambiguity. These |
| 71 |
are marked in the table as <quote>requires <literal>AS</literal></quote>. |
| 72 |
</para> |
| 73 |
|
| 74 |
<para> |
| 75 |
As a general rule, if you get spurious parser errors for commands |
| 76 |
that use any of the listed key words as an identifier, you should |
| 77 |
try quoting the identifier to see if the problem goes away. |
| 78 |
</para> |
| 79 |
|
| 80 |
<para> |
| 81 |
It is important to understand before studying <xref |
| 82 |
linkend="keywords-table"/> that the fact that a key word is not |
| 83 |
reserved in <productname>PostgreSQL</productname> does not mean that |
| 84 |
the feature related to the word is not implemented. Conversely, the |
| 85 |
presence of a key word does not indicate the existence of a feature. |
| 86 |
</para> |
| 87 |
|
| 88 |
&keywords-table; |
| 89 |
|
| 90 |
</appendix> |