add simple create table support
This commit is contained in:
parent
2938f642d3
commit
6802aaef5a
|
@ -232,7 +232,7 @@ fixing them in the syntax but leaving them till the semantic checking
|
|||
> -> String
|
||||
> -- ^ the SQL source to parse
|
||||
> -> Either ParseError Statement
|
||||
> parseStatement = wrapParse statement
|
||||
> parseStatement = wrapParse topLevelStatement
|
||||
|
||||
|
||||
> -- | Parses a list of statements, with semi colons between
|
||||
|
@ -1432,6 +1432,9 @@ TODO: change style
|
|||
> topLevelQueryExpr :: Parser QueryExpr
|
||||
> topLevelQueryExpr = queryExpr <??> (id <$ semi)
|
||||
|
||||
> topLevelStatement :: Parser Statement
|
||||
> topLevelStatement = statement <??> (id <$ semi)
|
||||
|
||||
-------------------------
|
||||
|
||||
= Statements
|
||||
|
@ -1441,6 +1444,7 @@ TODO: change style
|
|||
> [keyword_ "create"
|
||||
> *> choice
|
||||
> [createSchema
|
||||
> ,createTable
|
||||
> ]
|
||||
> ,keyword_ "drop"
|
||||
> *> choice
|
||||
|
@ -1457,6 +1461,14 @@ TODO: change style
|
|||
> createSchema = keyword_ "schema" >>
|
||||
> CreateSchema <$> names
|
||||
|
||||
> createTable :: Parser Statement
|
||||
> createTable = keyword_ "table" >>
|
||||
> CreateTable
|
||||
> <$> names
|
||||
> <*> parens (commaSep1 columnDef)
|
||||
> where
|
||||
> columnDef = ColumnDef <$> name <*> typeName
|
||||
|
||||
> dropSchema :: Parser Statement
|
||||
> dropSchema = keyword_ "schema" >>
|
||||
> DropSchema <$> names
|
||||
|
|
|
@ -453,6 +453,13 @@ which have been changed to try to improve the layout of the output.
|
|||
> statement _ (CreateSchema nm) =
|
||||
> text "create" <+> text "schema" <+> names nm
|
||||
|
||||
> statement _ (CreateTable nm cds) =
|
||||
> text "create" <+> text "table" <+> names nm
|
||||
> <+> parens (commaSep $ map cd cds)
|
||||
> where
|
||||
> cd (ColumnDef n t) = name n <+> typeName t
|
||||
|
||||
|
||||
> statement _ (DropSchema nm db) =
|
||||
> text "drop" <+> text "schema" <+> names nm <+> dropBehav db
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
> ,IdentityRestart(..)
|
||||
> ,InsertSource(..)
|
||||
> ,SetClause(..)
|
||||
> ,TableElement(..)
|
||||
> -- * Dialect
|
||||
> ,Dialect(..)
|
||||
> -- * Comment
|
||||
|
@ -392,8 +393,8 @@ I'm not sure if this is valid syntax or not.
|
|||
> -- ddl
|
||||
> CreateSchema [Name] -- XXX
|
||||
> | DropSchema [Name] DropBehaviour -- XXX
|
||||
> {- | CreateTable -- XXX
|
||||
> | AlterTable -- XXX
|
||||
> | CreateTable [Name] [TableElement]
|
||||
> {- | AlterTable -- XXX
|
||||
> | DropTable -- XXX
|
||||
> | CreateView -- XXX
|
||||
> | DropView -- XXX
|
||||
|
@ -486,6 +487,28 @@ I'm not sure if this is valid syntax or not.
|
|||
> | SetMultiple [[Name]] [ValueExpr]
|
||||
> deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
> data TableElement =
|
||||
> ColumnDef Name TypeName
|
||||
> (Maybe DefaultClause)
|
||||
> -- (Maybe ColumnConstraintDef)
|
||||
> -- (Maybe CollateClause)
|
||||
> -- | TableConstraintDef
|
||||
> deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
> {-data TableConstraintDef
|
||||
> deriving (Eq,Show,Read,Data,Typeable) -}
|
||||
|
||||
> data DefaultClause =
|
||||
> DefaultClause ValueExpr
|
||||
> | IdentityColumnSpec
|
||||
> | GenerationClause
|
||||
|
||||
> {-data ColumnConstraintDef =
|
||||
> | NotNullConstraint
|
||||
> | UniqueConstraint
|
||||
> | ReferencesConstraint
|
||||
> | CheckConstraint-}
|
||||
|
||||
--------------------------
|
||||
|
||||
> -- | Used to set the dialect used for parsing and pretty printing,
|
||||
|
|
|
@ -90,7 +90,10 @@ schema name can be quoted iden or unicode quoted iden
|
|||
[ WITH <system versioning clause> ]
|
||||
[ ON COMMIT <table commit action> ROWS ]
|
||||
|
||||
,(TestStatement SQL2011 "create table ( a int )"
|
||||
> ,(TestStatement SQL2011 "create table t (a int, b int);"
|
||||
> $ CreateTable [Name "t"]
|
||||
> [ColumnDef (Name "a") (TypeName [Name "int"])
|
||||
> ,ColumnDef (Name "b") (TypeName [Name "int"])])
|
||||
|
||||
|
||||
<table contents source> ::=
|
||||
|
@ -251,6 +254,16 @@ schema name can be quoted iden or unicode quoted iden
|
|||
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY
|
||||
[ <left paren> <common sequence generator options> <right paren> ]
|
||||
|
||||
generated always as identity
|
||||
generated by default as identity
|
||||
|
||||
generated always as identity (start with signed_numeric
|
||||
increment by n
|
||||
maxvalue n | no maxvalue
|
||||
minvalue n | no minvalue)
|
||||
|
||||
generated always (valueexpr)
|
||||
|
||||
<generation clause> ::=
|
||||
<generation rule> AS <generation expression>
|
||||
|
||||
|
|
Loading…
Reference in a new issue