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

186 lines
4.5 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
2019-07-07 14:46:39 +02:00
get good parser error messages.
2015-08-08 19:49:23 +02:00
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
2016-02-22 22:24:25 +01:00
Supports scalar expressions, aliases with optional 'as'.
2015-08-08 19:49:23 +02:00
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
2016-02-22 22:24:25 +01:00
Supports scalar expressions, group by (), cube, rollup, grouping
2015-08-08 19:49:23 +02:00
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
2016-02-22 22:24:25 +01:00
Supports scalar expressions, asc/desc and nulls first/last.
2015-08-08 19:49:23 +02:00
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'.
2016-02-22 22:24:25 +01:00
=== Scalar expressions
2015-08-08 19:49:23 +02:00
2016-02-22 22:24:25 +01:00
The scalar expressions type and parser is used in many contexts,
2015-08-08 19:49:23 +02:00
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.
2016-02-22 22:24:25 +01:00
The supported scalar expressions include:
2015-08-08 19:49:23 +02:00
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
2019-07-07 13:54:22 +02:00
* schemas
** create, drop + drop restrict
* tables
** create table
*** constraints: named, null, unique, primary key, foreign key (matches, on update/delete)
*** identity (the weird ansi version), defaults
*** defaults
** alter table
*** defaults, null, set data type, drop column, constraints
** drop table + restrict
** create, drop view
** create, alter, drop domain
*** defaults, constraints
** create, drop assertion
** create, alter, drop sequence
2015-08-08 19:49:23 +02:00
2015-08-08 20:24:18 +02:00
== Non-query DML
2015-08-08 19:49:23 +02:00
2019-07-07 13:54:22 +02:00
** delete
*** delete from
*** as alias
*** where
** truncate
*** with identity options
** insert
*** values, general queries, defaults
** update
*** including row updates
2015-08-08 19:49:23 +02:00
2015-08-08 20:24:18 +02:00
== Access Control
2015-08-08 19:49:23 +02:00
2019-07-07 13:54:22 +02:00
** grant privileges
*** all, grant option, table, domain, type, sequence, role, etc.
** revoke
** create role, drop role
2015-08-08 19:49:23 +02:00
2015-08-08 20:24:18 +02:00
== Transaction management
2015-08-08 19:49:23 +02:00
2019-07-07 13:54:22 +02:00
* begin, commit, rollback
* savepoints