Section 11 in Foundation This module covers the tests for parsing schema and DDL statements. > module Language.SQL.SimpleSQL.SQL2011Schema (sql2011SchemaTests) where > import Language.SQL.SimpleSQL.TestTypes > import Language.SQL.SimpleSQL.Syntax > sql2011SchemaTests :: TestItem > sql2011SchemaTests = Group "sql 2011 schema tests" > [ 11.1 ::= CREATE SCHEMA [ ] [ ... ] > (TestStatement SQL2011 "create schema my_schema" > $ CreateSchema [Name "my_schema"]) todo: schema name can have . schema name can be quoted iden or unicode quoted iden ::= | | | ::= | AUTHORIZATION | AUTHORIZATION ::= ::= DEFAULT CHARACTER SET ::= ::= | | | | | | | | | | | | | | | 11.2 ::= DROP SCHEMA ::= CASCADE | RESTRICT > ,(TestStatement SQL2011 "drop schema my_schema" > $ DropSchema [Name "my_schema"] DefaultDropBehaviour) > ,(TestStatement SQL2011 "drop schema my_schema cascade" > $ DropSchema [Name "my_schema"] Cascade) > ,(TestStatement SQL2011 "drop schema my_schema restrict" > $ DropSchema [Name "my_schema"] Restrict) 11.3
::= CREATE [
] TABLE
[ WITH ] [ ON COMMIT
ROWS ] > ,(TestStatement SQL2011 "create table t (a int, b int);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing [] > ,ColumnDef (Name "b") (TypeName [Name "int"]) Nothing []])
::=
| |
::= TEMPORARY ::= GLOBAL | LOCAL ::= SYSTEM VERSIONING defintely skip
::= PRESERVE | DELETE defintely skip
::=
[ {
}... ]
::= |
|
| ::= OF [ ] [ ] defintely skip ::= [ { }... ] defintely skip ::= |
| defintely skip ::= REF IS [ ] defintely skip ::= SYSTEM GENERATED | USER GENERATED | DERIVED defintely skip ::= defintely skip ::= WITH OPTIONS defintely skip ::= [ ] [ ] [ ... ] defintely skip ::= UNDER defintely skip ::= defintely skip ::=
defintely skip ::= LIKE
[ ] ::= ... ::= | | ::= INCLUDING IDENTITY | EXCLUDING IDENTITY ::= INCLUDING DEFAULTS | EXCLUDING DEFAULTS ::= INCLUDING GENERATED | EXCLUDING GENERATED ::= [ ] AS
::= WITH NO DATA | WITH DATA
::= defintely skip ::= | defintely skip ::= PERIOD FOR SYSTEM_TIME defintely skip ::= PERIOD FOR defintely skip ::= defintely skip ::= defintely skip ::= defintely skip 11.4 ::= [ ] [ | | | | ] [ ... ] [ ] ::= | ::= AS ROW START defintely skip ::= AS ROW END defintely skip ::= GENERATED ALWAYS defintely skip ::= [ ] [ ] ::= NOT NULL | | | can have more than one whitespace separated one constratint: optional name: constraint [Name] not null | unique | references | check todo: constraint characteristics > ,(TestStatement SQL2011 > "create table t (a int not null);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing NotNullConstraint]]) > ,(TestStatement SQL2011 > "create table t (a int constraint a_not_null not null);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef (Just [Name "a_not_null"]) NotNullConstraint]]) > ,(TestStatement SQL2011 > "create table t (a int unique);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing UniqueConstraint]]) > ,(TestStatement SQL2011 > "create table t (a int primary key);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing PrimaryKeyConstraint]]) references t(a,b) [ Full |partial| simepl] [perm: on update [cascade | set null | set default | restrict | no action] on delete "" > ,(TestStatement SQL2011 > "create table t (a int references u);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing DefaultReferenceMatch > DefaultReferentialAction DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u(a));" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] (Just $ Name "a") DefaultReferenceMatch > DefaultReferentialAction DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u match full);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing MatchFull > DefaultReferentialAction DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u match partial);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing MatchPartial > DefaultReferentialAction DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u match simple);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing MatchSimple > DefaultReferentialAction DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u on update cascade );" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing DefaultReferenceMatch > RefCascade DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u on update set null );" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing DefaultReferenceMatch > RefSetNull DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u on update set default );" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing DefaultReferenceMatch > RefSetDefault DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u on update no action );" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing DefaultReferenceMatch > RefNoAction DefaultReferentialAction]]) > ,(TestStatement SQL2011 > "create table t (a int references u on delete cascade );" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing DefaultReferenceMatch > DefaultReferentialAction RefCascade]]) > ,(TestStatement SQL2011 > "create table t (a int references u on update cascade on delete restrict );" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing DefaultReferenceMatch > RefCascade RefRestrict]]) > ,(TestStatement SQL2011 > "create table t (a int references u on delete restrict on update cascade );" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing $ ReferencesConstraint > [Name "u"] Nothing DefaultReferenceMatch > RefCascade RefRestrict]]) > ,(TestStatement SQL2011 > "create table t (a int check (a>5));" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing > [ConstraintDef Nothing > (CheckConstraint $ BinOp (Iden [Name "a"]) [Name ">"] (NumLit "5"))]]) check (valueexpr) ::= GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ] > ,(TestStatement SQL2011 "create table t (a int generated as identity);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) > (Just $ IdentityColumnSpec GeneratedDefault []) []]) > ,(TestStatement SQL2011 "create table t (a int generated always as identity);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) > (Just $ IdentityColumnSpec GeneratedAlways []) []]) > ,(TestStatement SQL2011 "create table t (a int generated by default as identity);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) > (Just $ IdentityColumnSpec GeneratedByDefault []) []]) > ,(TestStatement SQL2011 > "create table t (a int generated as identity\ > \ ( start with 5 increment by 5 maxvalue 500 minvalue 5 cycle ));" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) > (Just $ IdentityColumnSpec GeneratedDefault > [SGOStartWith 5 > ,SGOIncrementBy 5 > ,SGOMaxValue 500 > ,SGOMinValue 5 > ,SGOCycle]) []]) > ,(TestStatement SQL2011 > "create table t (a int generated as identity\ > \ ( start with -4 no maxvalue no minvalue no cycle ));" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) > (Just $ IdentityColumnSpec GeneratedDefault > [SGOStartWith (-4) > ,SGONoMaxValue > ,SGONoMinValue > ,SGONoCycle]) []]) I think is supposed to just whitespace separated. In db2 it seems to be csv, but the grammar here just seems to be whitespace separated, and it is just whitespace separated in oracle... Not completely sure though. Usually db2 is closer than oracle? generated always (valueexpr) ::= AS ::= GENERATED ALWAYS ::= > ,(TestStatement SQL2011 > "create table t (a int, \ > \ a2 int generated always as (a * 2));" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing [] > ,ColumnDef (Name "a2") (TypeName [Name "int"]) > (Just $ GenerationClause > (BinOp (Iden [Name "a"]) [Name "*"] (NumLit "2"))) []]) 11.5 ::= DEFAULT ::= | | USER | CURRENT_USER | CURRENT_ROLE | SESSION_USER | SYSTEM_USER | CURRENT_CATALOG | CURRENT_SCHEMA | CURRENT_PATH | > ,(TestStatement SQL2011 "create table t (a int default 0);" > $ CreateTable [Name "t"] > [ColumnDef (Name "a") (TypeName [Name "int"]) > (Just $ DefaultClause $ NumLit "0") []]) 11.6
::= [ ]
[ ]
::= | | 11.7 ::= [ ] | UNIQUE ( VALUE ) ::= UNIQUE | PRIMARY KEY ::= ::= WITHOUT OVERLAPS defintely skip 11.8 ::= FOREIGN KEY [ ] ::= REFERENCES [ MATCH ] [ ] ::= FULL | PARTIAL | SIMPLE ::= ::= PERIOD defintely skip ::=
[ [ ] ] ::= ::= PERIOD defintely skip ::= [ ] | [ ] ::= ON UPDATE ::= ON DELETE ::= CASCADE | SET NULL | SET DEFAULT | RESTRICT | NO ACTION 11.9 ::= CHECK 11.10 ::= ALTER TABLE
::= | | | | | | | | | 11.11 ::= ADD [ COLUMN ] alter table t add column a int alter table t add a int alter table t add a int unique not null check (a>0) 11.12 ::= ALTER [ COLUMN ] ::= | | | | | | | | | 11.13 ::= SET alter table t alter column c set default ... alter table t alter c set default ... 11.14 ::= DROP DEFAULT alter table t alter column c drop default 11.15 ::= SET NOT NULL alter table t alter column c set not null 11.16 ::= DROP NOT NULL alter table t alter column c drop not null 11.17 ::= ADD 11.18 ::= DROP SCOPE 11.19 ::= SET DATA TYPE alter table t alter column c set data type int; 11.20 ::= [ ... ] | ... ::= SET GENERATED { ALWAYS | BY DEFAULT } alter table t alter column c set generated always alter table t alter column c set generated by default ::= | SET alter table t alter column c restart alter table t alter column c restart with 4 (snl) alter table t alter column c set increment by minvalue maxvalue cycle 11.21 ::= DROP IDENTITY alter table t alter column c drop identity 11.22 ::= DROP EXPRESSION alter table t alter column c drop expression 11.23 ::= DROP [ COLUMN ] alter table t alter drop column c alter table t alter drop c restrict alter table t alter drop c cascade 11.24 ::= ADD
todo 11.25 ::= ALTER CONSTRAINT todo 11.26 ::= DROP CONSTRAINT todo 11.27 ::= ADD
[ ] defintely skip ::= ADD [ COLUMN ] ADD [ COLUMN ] defintely skip ::= defintely skip ::= defintely skip 11.28 ::= DROP defintely skip 11.29 ::= ADD defintely skip 11.30 ::= DROP SYSTEM VERSIONING defintely skip 11.31 ::= DROP TABLE
drop table t drop table t cascade drop table t restrict 11.32 ::= CREATE [ RECURSIVE ] VIEW
AS [ WITH [ ] CHECK OPTION ] ::= | ::= [ ] ::= OF [ ] [ ] ::= UNDER
::= [ { }... ] ::= | ::= WITH OPTIONS ::= CASCADED | LOCAL ::= 11.33 ::= DROP VIEW
11.34 ::= CREATE DOMAIN [ AS ] [ ] [ ... ] [ ] ::= [ ] [ ] 11.35 ::= ALTER DOMAIN ::= | | | 11.36 ::= SET 11.37 ::= DROP DEFAULT 11.38 ::= ADD 11.39 ::= DROP CONSTRAINT 11.40 ::= DROP DOMAIN 11.41 ::= CREATE CHARACTER SET [ AS ] [ ] ::= GET 11.42 ::= DROP CHARACTER SET 11.43 ::= CREATE COLLATION FOR FROM [ ] ::= ::= NO PAD | PAD SPACE 11.44 ::= DROP COLLATION 11.45 ::= CREATE TRANSLATION FOR TO FROM ::= ::= ::= | ::= ::= 11.46 ::= DROP TRANSLATION 11.47 ::= CREATE ASSERTION CHECK [ ] 11.48 ::= DROP ASSERTION [ ] 11.49 ::= CREATE TRIGGER ON
[ REFERENCING ] ::= BEFORE | AFTER | INSTEAD OF ::= INSERT | DELETE | UPDATE [ OF ] ::= ::= [ FOR EACH { ROW | STATEMENT } ] [ ] ::= WHEN ::= | BEGIN ATOMIC { }... END ::= ... ::= OLD [ ROW ] [ AS ] | NEW [ ROW ] [ AS ] | OLD TABLE [ AS ] | NEW TABLE [ AS ] ::= ::= ::= ::= ::= 11.50 ::= DROP TRIGGER 11.51 ::= CREATE TYPE ::= [ ] [ AS ] [ ] [ ] ::= [ ... ] ::= | | | | | | ::= UNDER ::= ::= | | ::= [ { }... ] ::= ::= INSTANTIABLE | NOT INSTANTIABLE ::= FINAL | NOT FINAL ::= | | ::= REF USING ::= REF FROM ::= REF IS SYSTEM GENERATED ::= CAST SOURCE AS REF WITH ::= ::= CAST REF AS SOURCE WITH ::= ::= [ { }... ] ::= CAST SOURCE AS DISTINCT WITH ::= ::= CAST DISTINCT AS SOURCE WITH ::= ::= [ { }... ] ::= | ::= [ SELF AS RESULT ] [ SELF AS LOCATOR ] [ ] ::= OVERRIDING 1 ::= [ INSTANCE | STATIC | CONSTRUCTOR ] METHOD [ SPECIFIC ] ::= [ ] ::= ... ::= | | | | 11.52 ::= [ ] [ ] ::= 11.53 ::= ALTER TYPE ::= | | | | 11.54 ::= ADD ATTRIBUTE 11.55 ::= DROP ATTRIBUTE RESTRICT 11.56 ::= ADD 11.57 ::= ADD 11.58 ::= DROP RESTRICT ::= [ INSTANCE | STATIC | CONSTRUCTOR ] METHOD 11.59 ::= DROP TYPE 11.60 ::= ::= | ::= CREATE ::= CREATE ::= PROCEDURE ::= { | } ::= [ [ { }... ] ] ::= [ ] [ ] [ RESULT ] [ DEFAULT ] ::= | ::= IN | OUT | INOUT ::= [ ] ::= AS LOCATOR ::= FUNCTION [ ] ::= SPECIFIC METHOD | [ INSTANCE | STATIC | CONSTRUCTOR ] METHOD [ ] FOR ::= [ ... ] ::= | | SPECIFIC | | | | | ::= NEW SAVEPOINT LEVEL | OLD SAVEPOINT LEVEL ::= DYNAMIC RESULT SETS ::= PARAMETER STYLE ::= STATIC DISPATCH ::= RETURNS ::= [ ] | ::= TABLE
::=
[ {
}... ]
::= ::= CAST FROM ::= [ ] ::= [ ] ::= | ::= [ ] ::= SQL SECURITY INVOKER | SQL SECURITY DEFINER ::= ::= EXTERNAL [ NAME ] [ ] [ ] [ ] ::= EXTERNAL SECURITY DEFINER | EXTERNAL SECURITY INVOKER | EXTERNAL SECURITY IMPLEMENTATION DEFINED ::= SQL | GENERAL ::= DETERMINISTIC | NOT DETERMINISTIC ::= NO SQL | CONTAINS SQL | READS SQL DATA | MODIFIES SQL DATA ::= RETURNS NULL ON NULL INPUT | CALLED ON NULL INPUT ::= ::= TRANSFORM GROUP { | } ::= ::= [ { }... ] ::= FOR TYPE 11.61 ::= ALTER ::= ... ::= | | | | | NAME ::= RESTRICT 11.62 ::= DROP 11.63 ::= CREATE CAST AS WITH [ AS ASSIGNMENT ] ::= ::= ::= 11.64 ::= DROP CAST AS 11.65 ::= CREATE ORDERING FOR ::= | ::= EQUALS ONLY BY ::= ORDER FULL BY ::= | | ::= RELATIVE WITH ::= MAP WITH ::= STATE [ ] ::= ::= 11.66 ::= DROP ORDERING FOR 11.67 ::= CREATE { TRANSFORM | TRANSFORMS } FOR ... ::= ::= ::= [ ] ::= | ::= TO SQL WITH ::= FROM SQL WITH ::= ::= 11.68 ::= ALTER { TRANSFORM | TRANSFORMS } FOR ... ::= ::= [ { }... ] ::= | 11.69 ::= ADD 11.70 ::= DROP [ ] ::= TO SQL | FROM SQL 11.71 ::= DROP { TRANSFORM | TRANSFORMS } FOR ::= ALL | ::= 11.72 ::= CREATE SEQUENCE [ ] ::= ... ::= | ::= ... ::= | ::= | | | ::= AS ::= START WITH ::= ::= INCREMENT BY ::= ::= MAXVALUE | NO MAXVALUE ::= ::= MINVALUE | NO MINVALUE ::= ::= CYCLE | NO CYCLE 11.73 ::= ALTER SEQUENCE ::= ... ::= | ::= RESTART [ WITH ] ::= 11.74 ::= DROP SEQUENCE > ]