Switch to: V14V13V12V11V10V9V8V7V6V5

LEXICAL TOKENS

  • SQL text consists of a sequence of SQL commands.
  • Commands
    • A command is composed of a sequence of tokens, terminated by a semicolon (“;”).
    • The end of the input stream also terminates a command.
  • Tokens
    • Which tokens are valid depends on the syntax of the particular command.
    • A token can be a keyword, an identifier, a quoted identifier, a literal (or constant), or a special character symbol.
    • Tokens are normally separated by whitespace (space, tab, newline) or syntax symbols.

Comments

Valentina SQL supports both single-line and multi-line comments.

Single Line Comments

Valentina SQL supports single-line comments using SQL92 and C++ style formatting. This comment applies to everything up to the next, new line symbol.

SELECT f1, f2, f3	-- this is SQL92 comment	 
FROM T		        // this IS C++ STYLE comment
WHERE f1 < 100

Multi-Line Comments

Valentina SQL supports also multi-line comments that allow you to comment across several lines. Multi-line comments cannot be nested. However, you can nest single-line comments inside of multi-line comments.

SELECT f1, SUM(f2) AS 'sum_f2'
FROM T		
/* WHERE f1 < 100	
GROUP BY f1             // single line comment
HAVING sum_f2 = 55 */

Keywords and Identifiers

SELECT * FROM MY_TABLE;
UPDATE MY_TABLE SET fldAge = 5;

Tokens such as SELECT, UPDATE, or VALUES are keywords, that is, words that have a fixed meaning in the SQL language. You can check list of Valentina SQL Keywords.

The tokens MY_TABLE, fldAge are examples of identifiers. They identify names of database objects, such as Tables, Columns, etc.

Keywords and identifiers have the same lexical structure, which is described by Lexer Rule IDENT:

IDENT : { LETTER | _ | @ } { LETTER | ‘_’ | DIGIT }*

This means that Lexer sees some IDENT, and needs to check the list of keywords to understand if it has a keyword or identifier.

QUOTED Identifiers

If you want to include spaces in the identifier, then you should wrap it with double-quotes. Please note, that the syntax with [name of person] is not supported anymore (since v.8.0).

"name of person"  -- SQL92

You can use double quotes inside a delimiter then you should “escape” them:

"name \"of\" person"
 
OR
 
"name ""of"" person"

Quoted identifiers can contain any character, except the character with code zero.

UINT

Valentina SQL supports unsigned numbers:

123	     123.456	123.456e12	123.456e-12		
                .456	   .456e12	   .456-e12	

String Literals

To include a string literal as a constant, wrap in single quotes.

‘this is a string literal‘

If a string literal appears inside single quotes, then you can use one of these two ways:

‘this is Peter’’s hat‘

‘this is Peter\’s hat‘	

‘this is C:\\disk\\games‘

The Valentina SQL parser will join two string literals into a single string if they follow one after the next and only use spaces to separate them:

‘abcde’   ‘fgh‘	 	=>	‘abcdefgh‘ 

String literal can contain non-English characters. The parser extracts strings as is and then passes them to the SQL engine.

Dollar-Quoted String Literals

[New in v14], PostgreSQL syntax.

In v14 Valentina DB has Stored Procedures written in JavaScript and Python.

While the standard syntax for specifying string constants is usually convenient, it can be difficult to understand when the desired string contains many single quotes, since each of those must be doubled. To allow more readable queries in such situations, we have added PostgreSQL-style, called “dollar quoting”, to write string constants. For example, here are two different ways to specify the string “Dianne's horse” using dollar-quoting

$$Dianne's horse$$
$SomeTag$Dianne's horse$SomeTag$

Note: Valentina DB so far does not allow nested tags, as PostgreSQL do. If you will need this, let us know.