
There is a second kind of identifier: the delimited identifier or quoted identifier. Therefore:Ī convention often used is to write key words in upper case and names in lower case, e.g.: Key words and unquoted identifiers are case insensitive. If this limit is problematic, it can be raised by changing the NAMEDATALEN constant in src/include/pg_config_manual.h. By default, NAMEDATALEN is 64 so the maximum identifier length is 63 bytes. The system uses no more than NAMEDATALEN-1 bytes of an identifier longer names can be written in commands, but they will be truncated. 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. 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. Subsequent characters in an identifier or key word can be letters, underscores, digits ( 0- 9), or dollar signs ( $). SQL identifiers and key words must begin with a letter ( a- z, but also letters with diacritical marks and non-Latin letters) or an underscore ( _). A complete list of key words can be found in Appendix C. 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.

Therefore they are sometimes simply called “ names”. They identify names of tables, columns, or other database objects, depending on the command they are used in. The tokens MY_TABLE and A are examples of identifiers. Tokens such as SELECT, UPDATE, or VALUES in the example above are examples of key words, that is, words that have a fixed meaning in the SQL language. The precise syntax rules for each command are described in Part VI.
#UNICODE CODEPOINTS UPDATE#
But for instance the UPDATE command always requires a SET token to appear in a certain position, and this particular variation of INSERT also requires a VALUES in order to be complete. The first few tokens are generally the command name, so in the above example we would usually speak of a “ SELECT”, an “ UPDATE”, and an “ INSERT” command.

The SQL syntax is not very consistent regarding what tokens identify commands and which are operands or parameters. They are not tokens, they are effectively equivalent to whitespace. This is a sequence of three commands, one per line (although this is not required more than one command can be on a line, and commands can usefully be split across lines).Īdditionally, comments can occur in SQL input. INSERT INTO MY_TABLE VALUES (3, 'hi there') Tokens are normally separated by whitespace (space, tab, newline), but need not be if there is no ambiguity (which is generally only the case if a special character is adjacent to some other token type).įor example, the following is (syntactically) valid SQL input:

Which tokens are valid depends on the syntax of the particular command.Ī token can be a key word, an identifier, a quoted identifier, a literal (or constant), or a special character symbol. The end of the input stream also terminates a command. A command is composed of a sequence of tokens, terminated by a semicolon ( “ ”). SQL input consists of a sequence of commands.
