SQL Tokens, Identifiers, Delimiters
SQL Tokens
SQL consists of lexical units called tokens. Tokens consist of identifiers, constants and keywords. Delimiters are used to separate tokens.
Identifiers
Identifiers are used to identify or name objects like tables, columns, schemas, and indexes. There are two kinds of identifiers - regular and delimited. CONNX can handle identifiers of up to 128 characters.
Regular identifiers are:
Not delimited by double quotes
Case insensitive
Comprised of only letters, digits and the underscore character
Delimited identifiers are:
Delimited by double quotes
Case sensitive
Comprised of letters, digits, and any of the following characters:
% & ' ( ) * + , - . / : ; < = > ? [ ]Use a delimited identifier if your object:
Contain blanks
Does not start with a letter
Is identical to a keyword
Is case-sensitive
Contains any of the following characters:
% & ' ( ) * + , - . / : ; < = > ? [ ]Examples:
Incorrect Indetifier | Correct Identifier | Explanation |
create view table as select TABLE_NAME,TABLE_TYPE from information_schema.tables where table_schema=USER; | create view "table" as select TABLE_NAME,TABLE_TYPE from information_schema.tables where table_schema=USER; | Table is a keyword and can not be used as a regular identifier. If it is used as a delimited identifier, it can specify a view name. |
select col1-1 from tab1; | select "col1-1" from tab1; | col1-1 is a numeric operation in select list and can not be used as a regular identifier. If it is used as a delimited identifier, it can specify a column name. |
Delimiters
A delimiter is used to separate the lexical units in the language for compiler processing. Delimiters are either spaces, control characters, comments, or special tokens. A comment must be preceded by two hyphens (--).
The following symbols are used as special tokens in SQL:
, | () | < | > | . |
: | = | + | - | * |
<> | <= | >= | / | ; |
? | ~> | ~< | ~= | " |
|| | | | | |