{- Section 11 in Foundation This module covers the tests for parsing schema and DDL statements. -} {-# LANGUAGE OverloadedStrings #-} module Language.SQL.SimpleSQL.SQL2011Schema (sql2011SchemaTests) where import Language.SQL.SimpleSQL.TestTypes import Language.SQL.SimpleSQL.Syntax import Language.SQL.SimpleSQL.TestRunners import Data.Text (Text) sql2011SchemaTests :: TestItem sql2011SchemaTests = Group "sql 2011 schema tests" [ {- 11.1 ::= CREATE SCHEMA [ ] [ ... ] -} s "create schema my_schema" $ CreateSchema [Name Nothing "my_schema"] {- todo: schema name can have . schema name can be quoted iden or unicode quoted iden add schema element support: create a list of schema elements then do pairwise combinations in schema element list to test ::= | | | ::= | AUTHORIZATION | AUTHORIZATION ::= ::= DEFAULT CHARACTER SET ::= ::= | | | | | | | | | | | | | | | 11.2 ::= DROP SCHEMA ::= CASCADE | RESTRICT -} ,s "drop schema my_schema" $ DropSchema [Name Nothing "my_schema"] DefaultDropBehaviour ,s "drop schema my_schema cascade" $ DropSchema [Name Nothing "my_schema"] Cascade ,s "drop schema my_schema restrict" $ DropSchema [Name Nothing "my_schema"] Restrict {- 11.3
::= CREATE [
] TABLE
[ WITH ] [ ON COMMIT
ROWS ] -} ,s "create table t (a int, b int);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableColumnDef $ ColumnDef (Name Nothing "b") (Just (TypeName [Name Nothing "int"])) []] False {-
::=
| |
::= 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 -} ,s "create table t (a int not null);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing ColNotNullConstraint]] False ,s "create table t (a int constraint a_not_null not null);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef (Just [Name Nothing "a_not_null"]) ColNotNullConstraint]] False ,s "create table t (a int unique);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing ColUniqueConstraint]] False ,s "create table t (a int primary key);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing (ColPrimaryKeyConstraint False)]] False ,testStatement ansi2011{ diAutoincrement = True } "create table t (a int primary key autoincrement);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing (ColPrimaryKeyConstraint True)]] False {- references t(a,b) [ Full |partial| simepl] [perm: on update [cascade | set null | set default | restrict | no action] on delete "" -} ,s "create table t (a int references u);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing DefaultReferenceMatch DefaultReferentialAction DefaultReferentialAction]] False ,s "create table t (a int references u(a));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] (Just $ Name Nothing "a") DefaultReferenceMatch DefaultReferentialAction DefaultReferentialAction]] False ,s "create table t (a int references u match full);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing MatchFull DefaultReferentialAction DefaultReferentialAction]] False ,s "create table t (a int references u match partial);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing MatchPartial DefaultReferentialAction DefaultReferentialAction]] False ,s "create table t (a int references u match simple);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing MatchSimple DefaultReferentialAction DefaultReferentialAction]] False ,s "create table t (a int references u on update cascade );" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing DefaultReferenceMatch RefCascade DefaultReferentialAction]] False ,s "create table t (a int references u on update set null );" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing DefaultReferenceMatch RefSetNull DefaultReferentialAction]] False ,s "create table t (a int references u on update set default );" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing DefaultReferenceMatch RefSetDefault DefaultReferentialAction]] False ,s "create table t (a int references u on update no action );" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing DefaultReferenceMatch RefNoAction DefaultReferentialAction]] False ,s "create table t (a int references u on delete cascade );" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing DefaultReferenceMatch DefaultReferentialAction RefCascade]] False ,s "create table t (a int references u on update cascade on delete restrict );" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing DefaultReferenceMatch RefCascade RefRestrict]] False ,s "create table t (a int references u on delete restrict on update cascade );" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColReferencesConstraint [Name Nothing "u"] Nothing DefaultReferenceMatch RefCascade RefRestrict]] False {- TODO: try combinations and permutations of column constraints and options -} ,s "create table t (a int check (a>5));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing (ColCheckConstraint $ BinOp (Iden [Name Nothing "a"]) [Name Nothing ">"] (NumLit "5"))]] False {- ::= GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ] -} ,s "create table t (a int generated always as identity);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColDefaultClause $ IdentityColumnSpec GeneratedAlways []]] False ,s "create table t (a int generated by default as identity);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColDefaultClause $ IdentityColumnSpec GeneratedByDefault []]] False ,s "create table t (a int generated always as identity\n\ \ ( start with 5 increment by 5 maxvalue 500 minvalue 5 cycle ));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColDefaultClause $ IdentityColumnSpec GeneratedAlways [SGOStartWith 5 ,SGOIncrementBy 5 ,SGOMaxValue 500 ,SGOMinValue 5 ,SGOCycle]]] False ,s "create table t (a int generated always as identity\n\ \ ( start with -4 no maxvalue no minvalue no cycle ));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColDefaultClause $ IdentityColumnSpec GeneratedAlways [SGOStartWith (-4) ,SGONoMaxValue ,SGONoMinValue ,SGONoCycle]]] False {- 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 ::= -} ,s "create table t (a int, \n\ \ a2 int generated always as (a * 2));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableColumnDef $ ColumnDef (Name Nothing "a2") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColDefaultClause $ GenerationClause (BinOp (Iden [Name Nothing "a"]) [Name Nothing "*"] (NumLit "2"))]] False {- 11.5 ::= DEFAULT ::= | | USER | CURRENT_USER | CURRENT_ROLE | SESSION_USER | SYSTEM_USER | CURRENT_CATALOG | CURRENT_SCHEMA | CURRENT_PATH | -} ,s "create table t (a int default 0);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColDefaultClause $ DefaultClause $ NumLit "0"]] False {- 11.6
::= [ ]
[ ]
::= | | 11.7 ::= [ ] | UNIQUE ( VALUE ) ::= UNIQUE | PRIMARY KEY ::= -} ,s "create table t (a int, unique (a));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef Nothing $ TableUniqueConstraint [Name Nothing "a"] ] False ,s "create table t (a int, constraint a_unique unique (a));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef (Just [Name Nothing "a_unique"]) $ TableUniqueConstraint [Name Nothing "a"] ] False -- todo: test permutations of column defs and table constraints ,s "create table t (a int, b int, unique (a,b));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableColumnDef $ ColumnDef (Name Nothing "b") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef Nothing $ TableUniqueConstraint [Name Nothing "a", Name Nothing "b"] ] False ,s "create table t (a int, b int, primary key (a,b));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableColumnDef $ ColumnDef (Name Nothing "b") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef Nothing $ TablePrimaryKeyConstraint [Name Nothing "a", Name Nothing "b"] ] False {- ::= WITHOUT OVERLAPS defintely skip 11.8 ::= FOREIGN KEY [ ] -} ,s "create table t (a int, b int,\n\ \ foreign key (a,b) references u(c,d) match full on update cascade on delete restrict );" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableColumnDef $ ColumnDef (Name Nothing "b") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef Nothing $ TableReferencesConstraint [Name Nothing "a", Name Nothing "b"] [Name Nothing "u"] (Just [Name Nothing "c", Name Nothing "d"]) MatchFull RefCascade RefRestrict ] False ,s "create table t (a int,\n\ \ constraint tfku1 foreign key (a) references u);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef (Just [Name Nothing "tfku1"]) $ TableReferencesConstraint [Name Nothing "a"] [Name Nothing "u"] Nothing DefaultReferenceMatch DefaultReferentialAction DefaultReferentialAction ] False ,testStatement ansi2011{ diNonCommaSeparatedConstraints = True } "create table t (a int, b int,\n\ \ foreign key (a) references u(c)\n\ \ foreign key (b) references v(d));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableColumnDef $ ColumnDef (Name Nothing "b") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef Nothing $ TableReferencesConstraint [Name Nothing "a"] [Name Nothing "u"] (Just [Name Nothing "c"]) DefaultReferenceMatch DefaultReferentialAction DefaultReferentialAction ,TableConstraintDef Nothing $ TableReferencesConstraint [Name Nothing "b"] [Name Nothing "v"] (Just [Name Nothing "d"]) DefaultReferenceMatch DefaultReferentialAction DefaultReferentialAction ] False ,testStatement ansi2011{ diWithoutRowidTables = True } "create table t (a int) without rowid;" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) []] True ,testStatement ansi2011{ diOptionalColumnTypes = True } "create table t (a,b);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") Nothing [] ,TableColumnDef $ ColumnDef (Name Nothing "b") Nothing [] ] False ,testStatement ansi2011{ diDefaultClausesAsConstraints = True } "create table t (a int default 1 default 2);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing $ ColDefaultClause $ DefaultClause $ NumLit "1" ,ColConstraintDef Nothing $ ColDefaultClause $ DefaultClause $ NumLit "2"]] False ,testStatement ansi2011{ diDefaultClausesAsConstraints = True } "create table t (a int not null default 2);" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [ColConstraintDef Nothing ColNotNullConstraint ,ColConstraintDef Nothing $ ColDefaultClause $ DefaultClause $ NumLit "2"]] False {- ::= 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 -} ,s "create table t (a int, b int, \n\ \ check (a > b));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableColumnDef $ ColumnDef (Name Nothing "b") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef Nothing $ TableCheckConstraint (BinOp (Iden [Name Nothing "a"]) [Name Nothing ">"] (Iden [Name Nothing "b"])) ] False ,s "create table t (a int, b int, \n\ \ constraint agtb check (a > b));" $ CreateTable [Name Nothing "t"] [TableColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] ,TableColumnDef $ ColumnDef (Name Nothing "b") (Just (TypeName [Name Nothing "int"])) [] ,TableConstraintDef (Just [Name Nothing "agtb"]) $ TableCheckConstraint (BinOp (Iden [Name Nothing "a"]) [Name Nothing ">"] (Iden [Name Nothing "b"])) ] False {- TODO: lots more combos of table elements and types and the other bits in a column def 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) -} ,s "alter table t add column a int" $ AlterTable [Name Nothing "t"] $ AddColumnDef $ ColumnDef (Name Nothing "a") (Just (TypeName [Name Nothing "int"])) [] {- todo: more add column 11.12 ::= ALTER [ COLUMN ] ::= | | | | | | | | | 11.13 ::= SET -} ,s "alter table t alter column c set default 0" $ AlterTable [Name Nothing "t"] $ AlterColumnSetDefault (Name Nothing "c") $ NumLit "0" {- 11.14 ::= DROP DEFAULT -} ,s "alter table t alter column c drop default" $ AlterTable [Name Nothing "t"] $ AlterColumnDropDefault (Name Nothing "c") {- 11.15 ::= SET NOT NULL -} ,s "alter table t alter column c set not null" $ AlterTable [Name Nothing "t"] $ AlterColumnSetNotNull (Name Nothing "c") {- 11.16 ::= DROP NOT NULL -} ,s "alter table t alter column c drop not null" $ AlterTable [Name Nothing "t"] $ AlterColumnDropNotNull (Name Nothing "c") {- 11.17 ::= ADD 11.18 ::= DROP SCOPE 11.19 ::= SET DATA TYPE -} ,s "alter table t alter column c set data type int;" $ AlterTable [Name Nothing "t"] $ AlterColumnSetDataType (Name Nothing "c") (TypeName [Name Nothing "int"]) {- 11.20 ::= [ ... ] | ... ::= SET GENERATED { ALWAYS | BY DEFAULT } so you have to write set generated for alter identity? and you have to use always or by default makes no sense: if you just want to restart you have to explicitly set the always or by default? you can't just leave it unchanged? you don't write as identity like with create table, this is wrong: alter table t alter column c set generated always as identity but these are ok? 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 set generated always restart alter table t alter column c set generated always restart with 4 you can just write restart but to write others you have to repeat set? each time? alter table t alter column c set generated always set increment by 5 set minvalue 0 set maxvalue 5 set cycle restart with 5 (no set before the restart in create table, it looks like this: c int generated generated always as identity (increment by 5 minvalue 0 maxvalue 5 cycle restart with 5) why gratuituous differences??? is there no way to do this: alter table t alter column c set generated as (a * 3) ?? UPDATE: alter sequence uses same syntax as create sequence, which is the same sytnax as identity in create table, so overrule the sql standard and use the same syntax in alter identity. PLAN: TODO don't implement alter table alter column generated now review the syntax for generated in db2, oracle, sql server, postgres, others? observe which features are supported, and the consistency between create table and alter table try to find some people to ask if the standard really is this much of a mess or I have misunderstood the grammer, or maybe there is a good reason for the inconsistencies? 11.21 ::= DROP IDENTITY alter table t alter column c drop identity included in the generated plan above 11.22 ::= DROP EXPRESSION alter table t alter column c drop expression included in the generated plan above 11.23 ::= DROP [ COLUMN ] -} ,s "alter table t drop column c" $ AlterTable [Name Nothing "t"] $ DropColumn (Name Nothing "c") DefaultDropBehaviour ,s "alter table t drop c cascade" $ AlterTable [Name Nothing "t"] $ DropColumn (Name Nothing "c") Cascade ,s "alter table t drop c restrict" $ AlterTable [Name Nothing "t"] $ DropColumn (Name Nothing "c") Restrict {- 11.24 ::= ADD
-} ,s "alter table t add constraint c unique (a,b)" $ AlterTable [Name Nothing "t"] $ AddTableConstraintDef (Just [Name Nothing "c"]) $ TableUniqueConstraint [Name Nothing "a", Name Nothing "b"] ,s "alter table t add unique (a,b)" $ AlterTable [Name Nothing "t"] $ AddTableConstraintDef Nothing $ TableUniqueConstraint [Name Nothing "a", Name Nothing "b"] {- 11.25 ::= ALTER CONSTRAINT todo 11.26 ::= DROP CONSTRAINT -} ,s "alter table t drop constraint c" $ AlterTable [Name Nothing "t"] $ DropTableConstraintDef [Name Nothing "c"] DefaultDropBehaviour ,s "alter table t drop constraint c restrict" $ AlterTable [Name Nothing "t"] $ DropTableConstraintDef [Name Nothing "c"] Restrict {- 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
-} ,s "drop table t" $ DropTable [Name Nothing "t"] DefaultDropBehaviour ,s "drop table t restrict" $ DropTable [Name Nothing "t"] Restrict {- 11.32 ::= CREATE [ RECURSIVE ] VIEW
AS [ WITH [ ] CHECK OPTION ] ::= | ::= [ ] ::= OF [ ] [ ] ::= UNDER
::= [ { }... ] ::= | ::= WITH OPTIONS ::= CASCADED | LOCAL ::= -} ,s "create view v as select * from t" $ CreateView False [Name Nothing "v"] Nothing (toQueryExpr $ makeSelect {msSelectList = [(Star, Nothing)] ,msFrom = [TRSimple [Name Nothing "t"]] }) Nothing ,s "create recursive view v as select * from t" $ CreateView True [Name Nothing "v"] Nothing (toQueryExpr $ makeSelect {msSelectList = [(Star, Nothing)] ,msFrom = [TRSimple [Name Nothing "t"]] }) Nothing ,s "create view v(a,b) as select * from t" $ CreateView False [Name Nothing "v"] (Just [Name Nothing "a", Name Nothing "b"]) (toQueryExpr $ makeSelect {msSelectList = [(Star, Nothing)] ,msFrom = [TRSimple [Name Nothing "t"]] }) Nothing ,s "create view v as select * from t with check option" $ CreateView False [Name Nothing "v"] Nothing (toQueryExpr $ makeSelect {msSelectList = [(Star, Nothing)] ,msFrom = [TRSimple [Name Nothing "t"]] }) (Just DefaultCheckOption) ,s "create view v as select * from t with cascaded check option" $ CreateView False [Name Nothing "v"] Nothing (toQueryExpr $ makeSelect {msSelectList = [(Star, Nothing)] ,msFrom = [TRSimple [Name Nothing "t"]] }) (Just CascadedCheckOption) ,s "create view v as select * from t with local check option" $ CreateView False [Name Nothing "v"] Nothing (toQueryExpr $ makeSelect {msSelectList = [(Star, Nothing)] ,msFrom = [TRSimple [Name Nothing "t"]] }) (Just LocalCheckOption) {- 11.33 ::= DROP VIEW
-} ,s "drop view v" $ DropView [Name Nothing "v"] DefaultDropBehaviour ,s "drop view v cascade" $ DropView [Name Nothing "v"] Cascade {- 11.34 ::= CREATE DOMAIN [ AS ] [ ] [ ... ] [ ] ::= [ ] [ ] -} ,s "create domain my_int int" $ CreateDomain [Name Nothing "my_int"] (TypeName [Name Nothing "int"]) Nothing [] ,s "create domain my_int as int" $ CreateDomain [Name Nothing "my_int"] (TypeName [Name Nothing "int"]) Nothing [] ,s "create domain my_int int default 0" $ CreateDomain [Name Nothing "my_int"] (TypeName [Name Nothing "int"]) (Just (NumLit "0")) [] ,s "create domain my_int int check (value > 5)" $ CreateDomain [Name Nothing "my_int"] (TypeName [Name Nothing "int"]) Nothing [(Nothing ,BinOp (Iden [Name Nothing "value"]) [Name Nothing ">"] (NumLit "5"))] ,s "create domain my_int int constraint gt5 check (value > 5)" $ CreateDomain [Name Nothing "my_int"] (TypeName [Name Nothing "int"]) Nothing [(Just [Name Nothing "gt5"] ,BinOp (Iden [Name Nothing "value"]) [Name Nothing ">"] (NumLit "5"))] {- 11.35 ::= ALTER DOMAIN ::= | | | 11.36 ::= SET -} ,s "alter domain my_int set default 0" $ AlterDomain [Name Nothing "my_int"] $ ADSetDefault $ NumLit "0" {- 11.37 ::= DROP DEFAULT -} ,s "alter domain my_int drop default" $ AlterDomain [Name Nothing "my_int"] $ ADDropDefault {- 11.38 ::= ADD -} ,s "alter domain my_int add check (value > 6)" $ AlterDomain [Name Nothing "my_int"] $ ADAddConstraint Nothing $ BinOp (Iden [Name Nothing "value"]) [Name Nothing ">"] (NumLit "6") ,s "alter domain my_int add constraint gt6 check (value > 6)" $ AlterDomain [Name Nothing "my_int"] $ ADAddConstraint (Just [Name Nothing "gt6"]) $ BinOp (Iden [Name Nothing "value"]) [Name Nothing ">"] (NumLit "6") {- 11.39 ::= DROP CONSTRAINT -} ,s "alter domain my_int drop constraint gt6" $ AlterDomain [Name Nothing "my_int"] $ ADDropConstraint [Name Nothing "gt6"] {- 11.40 ::= DROP DOMAIN -} ,s "drop domain my_int" $ DropDomain [Name Nothing "my_int"] DefaultDropBehaviour ,s "drop domain my_int cascade" $ DropDomain [Name Nothing "my_int"] Cascade {- 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 [ ] -} ,s "create assertion t1_not_empty CHECK ((select count(*) from t1) > 0);" $ CreateAssertion [Name Nothing "t1_not_empty"] $ BinOp (SubQueryExpr SqSq $ toQueryExpr $ makeSelect {msSelectList = [(App [Name Nothing "count"] [Star],Nothing)] ,msFrom = [TRSimple [Name Nothing "t1"]] }) [Name Nothing ">"] (NumLit "0") {- 11.48 ::= DROP ASSERTION [ ] -} ,s "drop assertion t1_not_empty;" $ DropAssertion [Name Nothing "t1_not_empty"] DefaultDropBehaviour ,s "drop assertion t1_not_empty cascade;" $ DropAssertion [Name Nothing "t1_not_empty"] Cascade {- 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 -} ,s "create sequence seq" $ CreateSequence [Name Nothing "seq"] [] ,s "create sequence seq as bigint" $ CreateSequence [Name Nothing "seq"] [SGODataType $ TypeName [Name Nothing "bigint"]] ,s "create sequence seq as bigint start with 5" $ CreateSequence [Name Nothing "seq"] [SGOStartWith 5 ,SGODataType $ TypeName [Name Nothing "bigint"] ] {- 11.73 ::= ALTER SEQUENCE ::= ... ::= | ::= RESTART [ WITH ] ::= -} ,s "alter sequence seq restart" $ AlterSequence [Name Nothing "seq"] [SGORestart Nothing] ,s "alter sequence seq restart with 5" $ AlterSequence [Name Nothing "seq"] [SGORestart $ Just 5] ,s "alter sequence seq restart with 5 increment by 5" $ AlterSequence [Name Nothing "seq"] [SGORestart $ Just 5 ,SGOIncrementBy 5] {- 11.74 ::= DROP SEQUENCE -} ,s "drop sequence seq" $ DropSequence [Name Nothing "seq"] DefaultDropBehaviour ,s "drop sequence seq restrict" $ DropSequence [Name Nothing "seq"] Restrict ] s :: HasCallStack => Text -> Statement -> TestItem s src ast = testStatement ansi2011 src ast