Simple SQL Parser supported SQL

Overview

This page has more details on the supported SQL in simple-sql-parser.

See the simple-sql-parser test cases page for examples.

The target dialect of SQL at this time is ISO/ANSI SQL:2011. The parser supports queries, DDL, non-query DML, access control and transaction management syntax. The parser and syntax does not follow the standard grammar closely - they permit a lot of things which the grammar in the standard forbids. The intended usage is that an additional pass over the ast can be made if you want to carefully prohibit everything that the standard doesn’t allow.

Apart from this permissiveness, some work has been put into trying to get good parser error messages.

Queries

Select lists

Supports scalar expressions, aliases with optional ‘as’.

Set quantifiers on select

Supports ‘select distinct’ and explicit ‘select all’.

From clause

Group by clause

Supports scalar expressions, group by (), cube, rollup, grouping parentheses and grouping sets with nested grouping expressions.

Order by clause

Supports scalar expressions, asc/desc and nulls first/last.

Offset and fetch

Supports ‘offset n rows’ and ‘fetch first n rows only’.

Set operators

Union, except, intersect + all/distinct and corresponding.

Table value constructor

Example: ‘values (1,2),(3,4)’.

Explicit table

Example: ‘table t’, which is shorthand for ‘select * from t’.

Scalar expressions

The scalar expressions type and parser is used in many contexts, including:

This doesn’t exactly follow the ANSI Standards, which have separate grammars for most of these.

The supported scalar expressions include:

DDL

Non-query DML

Access Control

Transaction management