1
Fork 0
simple-sql-parser/website/supported_sql.asciidoc

157 lines
3.7 KiB
Plaintext
Raw Normal View History

2015-08-08 19:49:23 +02:00
2015-08-08 20:24:18 +02:00
:toc: right
:sectnums:
:toclevels: 10
:source-highlighter: pygments
= simple-sql-parser supported SQL
== Overview
2015-08-08 19:49:23 +02:00
This page has more details on the supported SQL in simple-sql-parser.
2015-08-08 20:24:18 +02:00
See the link:test_cases.html[simple-sql-parser test cases] page for
2015-08-08 19:49:23 +02:00
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
2015-08-08 19:49:23 +02:00
prohibit everything that the standard doesn't allow.
Apart from this permissiveness, some work has been put into trying to
get the best parser error messages possible.
2015-08-08 20:24:18 +02:00
== Queries
2015-08-08 19:49:23 +02:00
2015-08-08 20:24:18 +02:00
=== Select lists
2015-08-08 19:49:23 +02:00
Supports value expressions, aliases with optional 'as'.
Doesn't support 'select * as (a,b,c) from t' yet.
2015-08-08 20:24:18 +02:00
=== Set quantifiers on select
2015-08-08 19:49:23 +02:00
Supports 'select distinct' and explicit 'select all'.
2015-08-08 20:24:18 +02:00
=== From clause
2015-08-08 19:49:23 +02:00
* aliases
* subqueries
* functions
* joins
- natural
- inner
- left/right/full outer
- cross
- on expressions
- using lists
- lateral
2015-08-08 20:24:18 +02:00
=== Group by clause
2015-08-08 19:49:23 +02:00
Supports value expressions, group by (), cube, rollup, grouping
parentheses and grouping sets with nested grouping expressions.
2015-08-08 20:24:18 +02:00
=== Order by clause
2015-08-08 19:49:23 +02:00
Supports value expressions, asc/desc and nulls first/last.
2015-08-08 20:24:18 +02:00
=== Offset and fetch
2015-08-08 19:49:23 +02:00
Supports 'offset n rows' and 'fetch first n rows only'.
2015-08-08 20:24:18 +02:00
=== Set operators
2015-08-08 19:49:23 +02:00
Union, except, intersect + all/distinct and corresponding.
2015-08-08 20:24:18 +02:00
=== Table value constructor
2015-08-08 19:49:23 +02:00
For example: values (1,2),(3,4).
2015-08-08 20:24:18 +02:00
=== Explicit table
2015-08-08 19:49:23 +02:00
For example: 'table t', which is shorthand for 'select * from t'.
2015-08-08 20:24:18 +02:00
=== Value expressions
2015-08-08 19:49:23 +02:00
The value expressions type and parser is used in many contexts,
including:
* select lists;
* where clause expressions;
* group by clause expressions;
* having clause expressions;
* order by clause expressions;
* offset and fetch clause expressions;
* table value constructors.
This doesn't exactly follow the ANSI Standards, which have separate
grammars for most of these.
The supported value expressions include:
2015-08-08 20:24:18 +02:00
* basic string literals in single quotes
2015-08-08 19:49:23 +02:00
* number literals: digits.digitse+-exp
* explicitly typed literal, e.g. int '3'
* binary operators
- comparisons: = != <> <= >= < >
- arithmetic: + - / * % ^
- logic: and, or
- bitwise: & | (and ^ as above)
- string: ||, like, not like
- other: overlaps, is similar to, is not similar too, is distinct
from, is not distinct from
* prefix unary operators
- +, -
- not
- ~
* postfix unary
- is null, is not null
- is true, is not true, is false, is not false, is unknown, is not unknown
* other operators
- extract (extract(day from dt))
- position (position string1 in string2)
- substring (substring(x from 2 for 4))
- convert (convert(string using conversion))
- translate (translate(string using translation))
- overlay (overlay (string placing embedded_string from start for
length))
- trim (trim(leading '_' from s))
- between (a between 1 and 5)
- in list (a in (1,2,3,4))
- cast (cast(a as int))
* subqueries
- in subquery
- any/some/all
- exists
* case expressions
* parentheses
* quoted and unquoted identifiers
* a.b qualified identifiers
2015-08-08 20:24:18 +02:00
* \*, a.*
2015-08-08 19:49:23 +02:00
* functions: f(a,b)
* aggregates: agg(distinct a order by b)
* window functions: sum(x) over (partition by y order by z)
plus some explicit frame support (same as in postgres 9.3)
* row constructors, e.g. where (a,b) = any (select a,b from t)
* ? used in parameterized queries
2015-08-08 20:24:18 +02:00
== DDL
2015-08-08 19:49:23 +02:00
todo
2015-08-08 20:24:18 +02:00
== Non-query DML
2015-08-08 19:49:23 +02:00
todo
2015-08-08 20:24:18 +02:00
== Access Control
2015-08-08 19:49:23 +02:00
todo
2015-08-08 20:24:18 +02:00
== Transaction management
2015-08-08 19:49:23 +02:00
todo