zone="sql-syntax-identifiers">
<primary>identifier</primary>
<secondary>syntax of</secondary>
</indexterm>
<indexterm zone="sql-syntax-identifiers">
<primary>name</primary>
<secondary>syntax of</secondary>
</indexterm>
<indexterm zone="sql-syntax-identifiers">
<primary>key word</primary>
<secondary>syntax of</secondary>
</indexterm>
<para>
Tokens such as <token>SELECT</token>, <token>UPDATE</token>, or
<token>VALUES</token> in the example above are examples of
<firstterm>key words</firstterm>, that is, words that have a fixed
meaning in the SQL language. The tokens <token>MY_TABLE</token>
and <token>A</token> are examples of
<firstterm>identifiers</firstterm>. They identify names of
tables, columns, or other database objects, depending on the
command they are used in. Therefore they are sometimes simply
called <quote>names</quote>. Key words and identifiers have the
same lexical structure, meaning that one cannot know whether a
token is an identifier or a key word without knowing the language.
A complete list of key words can be found in <xref
linkend="sql-keywords-appendix"/>.
</para>
<para>
SQL identifiers and key words must begin with a letter
(<literal>a</literal>-<literal>z</literal>, but also letters with
diacritical marks and non-Latin letters) or an underscore
(<literal>_</literal>). Subsequent characters in an identifier or
key word can be letters, underscores, digits
(<literal>0</literal>-<literal>9</literal>), or dollar signs
(<literal>$</literal>). Note that dollar signs are not allowed in identifiers
according to the letter of the SQL standard, so their use might render
applications less portable.
The SQL standard will not define a key word that contains
digits or starts or ends with an underscore, so identifiers of this
form are safe against possible conflict with future extensions of the
standard.
</para>
<para>
<indexterm><primary>identifier</primary><secondary>length</secondary></indexterm>
The system uses no more than <symbol>NAMEDATALEN</symbol>-1
bytes of an identifier; longer names can be written in
commands, but they will be truncated. By default,
<symbol>NAMEDATALEN</symbol> is 64 so the maximum identifier
length is 63 bytes. If this limit is problematic, it can be raised by
changing the <symbol>NAMEDATALEN</symbol> constant in
<filename>src/include/pg_config_manual.h</filename>.
</para>
<para>
<indexterm>
<primary>case sensitivity</primary>
<secondary>of SQL commands</secondary>
</indexterm>
Key words and unquoted identifiers are case-insensitive. Therefore:
<programlisting>
UPDATE MY_TABLE SET A = 5;
</programlisting>
can equivalently be written as:
<programlisting>
uPDaTE my_TabLE SeT a = 5;
</programlisting>
A convention often used is to write key words in upper
case and names in lower case, e.g.:
<programlisting>
UPDATE my_table SET a = 5;
</programlisting>
</para>
<para>
<indexterm>
<primary>quotation marks</primary>
<secondary>and identifiers</secondary>
</indexterm>
There is a second kind of identifier: the <firstterm>delimited
identifier</firstterm> or <firstterm>quoted
identifier</firstterm>. It is formed by enclosing an arbitrary
sequence of characters in double-quotes
(<literal>"</literal>). <!-- " font-lock mania --> A delimited
identifier is always an identifier, never a key word. So
<literal>"select"</literal> could be used to refer to a column or
table named <quote>select</quote>, whereas an unquoted
<literal>select</literal> would be taken as a key word and
would therefore provoke a parse error when used where a table or
column name is expected. The example can be written with quoted
identifiers like this:
<programlisting>
UPDATE "my_table" SET "a" = 5;
</programlisting>