From dfa84072dce3ac0fb908ede3f5addbbf4c076d79 Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Sat, 1 Aug 2015 20:26:00 +0300 Subject: [PATCH] start adding basic dml parser and pretty printer for statements add query statement add support for insert update delete truncate bonus ddl: limited create schema drop schema add grammar notes to the new test files --- Language/SQL/SimpleSQL/Parser.lhs | 124 +- Language/SQL/SimpleSQL/Pretty.lhs | 76 +- Language/SQL/SimpleSQL/Syntax.lhs | 114 +- simple-sql-parser.cabal | 5 +- tools/Language/SQL/SimpleSQL/QueryExprs.lhs | 4 +- .../SQL/SimpleSQL/SQL2011AccessControl.lhs | 107 + tools/Language/SQL/SimpleSQL/SQL2011Bits.lhs | 174 +- .../SQL/SimpleSQL/SQL2011DataManipulation.lhs | 2277 +---------------- .../Language/SQL/SimpleSQL/SQL2011Queries.lhs | 3 + .../Language/SQL/SimpleSQL/SQL2011Schema.lhs | 23 +- tools/Language/SQL/SimpleSQL/TestTypes.lhs | 3 +- tools/Language/SQL/SimpleSQL/Tests.lhs | 6 +- tools/SimpleSqlParserTool.lhs | 6 +- 13 files changed, 684 insertions(+), 2238 deletions(-) diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index eb046b1..13d219b 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -179,7 +179,8 @@ fixing them in the syntax but leaving them till the semantic checking > module Language.SQL.SimpleSQL.Parser > (parseQueryExpr > ,parseValueExpr -> ,parseQueryExprs +> ,parseStatement +> ,parseStatements > ,ParseError(..)) where > import Control.Monad.Identity (Identity) @@ -220,9 +221,23 @@ fixing them in the syntax but leaving them till the semantic checking > -> Either ParseError QueryExpr > parseQueryExpr = wrapParse topLevelQueryExpr -> -- | Parses a list of query expressions, with semi colons between +> -- | Parses a statement, trailing semicolon optional. +> parseStatement :: Dialect +> -- ^ dialect of SQL to use +> -> FilePath +> -- ^ filename to use in error messages +> -> Maybe (Int,Int) +> -- ^ line number and column number of the first character +> -- in the source to use in error messages +> -> String +> -- ^ the SQL source to parse +> -> Either ParseError Statement +> parseStatement = wrapParse statement + + +> -- | Parses a list of statements, with semi colons between > -- them. The final semicolon is optional. -> parseQueryExprs :: Dialect +> parseStatements :: Dialect > -- ^ dialect of SQL to use > -> FilePath > -- ^ filename to use in error messages @@ -231,8 +246,8 @@ fixing them in the syntax but leaving them till the semantic checking > -- in the source to use in error messages > -> String > -- ^ the SQL source to parse -> -> Either ParseError [QueryExpr] -> parseQueryExprs = wrapParse queryExprs +> -> Either ParseError [Statement] +> parseStatements = wrapParse statements > -- | Parses a value expression. > parseValueExpr :: Dialect @@ -701,7 +716,15 @@ all the value expressions which start with an identifier > idenExpr = > -- todo: work out how to left factor this > try (TypedLit <$> typeName <*> stringTokExtend) +> <|> multisetSetFunction > <|> (names <**> option Iden app) +> where +> -- this is a special case because set is a reserved keyword +> -- and the names parser won't parse it +> multisetSetFunction = +> App [Name "set"] . (:[]) <$> +> (try (keyword_ "set" *> openParen) +> *> valueExpr <* closeParen) === special @@ -1409,16 +1432,93 @@ TODO: change style > topLevelQueryExpr :: Parser QueryExpr > topLevelQueryExpr = queryExpr (id <$ semi) -wrapper to parse a series of query exprs from a single source. They -must be separated by semicolon, but for the last expression, the -trailing semicolon is optional. +------------------------- + += Statements + +> statement :: Parser Statement +> statement = choice +> [keyword_ "create" +> *> choice +> [createSchema +> ] +> ,keyword_ "drop" +> *> choice +> [dropSchema +> ] +> ,delete +> ,truncateSt +> ,insert +> ,update +> ,SelectStatement <$> queryExpr +> ] + +> createSchema :: Parser Statement +> createSchema = keyword_ "schema" >> +> CreateSchema <$> names + +> dropSchema :: Parser Statement +> dropSchema = keyword_ "schema" >> +> DropSchema <$> names +> <*> dropBehaviour + +> delete :: Parser Statement +> delete = keywords_ ["delete","from"] >> +> Delete +> <$> names +> <*> optionMaybe (optional (keyword_ "as") *> name) +> <*> optionMaybe (keyword_ "where" *> valueExpr) + +> truncateSt :: Parser Statement +> truncateSt = keywords_ ["truncate", "table"] >> +> Truncate +> <$> names +> <*> option DefaultIdentityRestart +> (ContinueIdentity <$ keywords_ ["continue","identity"] +> <|> RestartIdentity <$ keywords_ ["restart","identity"]) + +> insert :: Parser Statement +> insert = keywords_ ["insert", "into"] >> +> Insert +> <$> names +> <*> optionMaybe (parens $ commaSep1 name) +> <*> (DefaultInsertValues <$ keywords_ ["default", "values"] +> <|> InsertQuery <$> queryExpr) + +> update :: Parser Statement +> update = keywords_ ["update"] >> +> Update +> <$> names +> <*> optionMaybe (optional (keyword_ "as") *> name) +> <*> (keyword_ "set" *> commaSep1 setClause) +> <*> optionMaybe (keyword_ "where" *> valueExpr) +> where +> setClause = multipleSet <|> singleSet +> multipleSet = SetMultiple +> <$> parens (commaSep1 names) +> <*> (symbol "=" *> parens (commaSep1 valueExpr)) +> singleSet = Set +> <$> names +> <*> (symbol "=" *> valueExpr) + +> dropBehaviour :: Parser DropBehaviour +> dropBehaviour = +> option DefaultDropBehaviour +> (Restrict <$ keyword_ "restrict" +> <|> Cascade <$ keyword_ "cascade") + +---------------------------- + +wrapper to parse a series of statements. They must be separated by +semicolon, but for the last statement, the trailing semicolon is +optional. TODO: change style -> queryExprs :: Parser [QueryExpr] -> queryExprs = (:[]) <$> queryExpr +> statements :: Parser [Statement] +> statements = (:[]) <$> statement > >>= optionSuffix ((semi *>) . pure) -> >>= optionSuffix (\p -> (p++) <$> queryExprs) +> >>= optionSuffix (\p -> (p++) <$> statements) ---------------------------------------------- @@ -1884,7 +1984,7 @@ means). > ,"select" > ,"sensitive" > --,"session_user" -> --,"set" +> ,"set" > ,"similar" > ,"smallint" > --,"some" diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index 0351fa9..039db76 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -5,7 +5,8 @@ > module Language.SQL.SimpleSQL.Pretty > (prettyQueryExpr > ,prettyValueExpr -> ,prettyQueryExprs +> ,prettyStatement +> ,prettyStatements > ) where TODO: there should be more comments in this file, especially the bits @@ -26,10 +27,14 @@ which have been changed to try to improve the layout of the output. > prettyValueExpr :: Dialect -> ValueExpr -> String > prettyValueExpr d = render . valueExpr d -> -- | Convert a list of query exprs to concrete syntax. A semi colon -> -- is inserted after each query expr. -> prettyQueryExprs :: Dialect -> [QueryExpr] -> String -> prettyQueryExprs d = render . vcat . map ((<> text ";\n") . queryExpr d) +> -- | Convert a statement ast to concrete syntax. +> prettyStatement :: Dialect -> Statement -> String +> prettyStatement d = render . statement d + +> -- | Convert a list of statements to concrete syntax. A semi colon +> -- is inserted after each statement. +> prettyStatements :: Dialect -> [Statement] -> String +> prettyStatements d = render . vcat . map ((<> text ";\n") . statement d) = value expressions @@ -438,6 +443,67 @@ which have been changed to try to improve the layout of the output. > NullsFirst -> text "nulls" <+> text "first" > NullsLast -> text "nulls" <+> text "last") += statements + +> statement :: Dialect -> Statement -> Doc + + +== ddl + +> statement _ (CreateSchema nm) = +> text "create" <+> text "schema" <+> names nm + +> statement _ (DropSchema nm db) = +> text "drop" <+> text "schema" <+> names nm <+> dropBehav db + +== dml + +> statement d (SelectStatement q) = queryExpr d q + +> statement d (Delete t a w) = +> text "delete" <+> text "from" +> <+> names t <+> maybe empty (\x -> text "as" <+> name x) a +> <+> maybeValueExpr d "where" w + +> statement _ (Truncate t ir) = +> text "truncate" <+> text "table" <+> names t +> <+> case ir of +> DefaultIdentityRestart -> empty +> ContinueIdentity -> text "continue" <+> text "identity" +> RestartIdentity -> text "restart" <+> text "identity" + +> statement d (Insert t cs s) = +> text "insert" <+> text "into" <+> names t +> <+> maybe empty (\cs' -> parens (commaSep $ map name cs')) cs +> <+> case s of +> DefaultInsertValues -> text "default" <+> text "values" +> InsertQuery q -> queryExpr d q + +> statement d (Update t a sts whr) = +> text "update" <+> names t +> <+> maybe empty (\x -> text "as" <+> name x) a +> <+> text "set" <+> commaSep (map sc sts) +> <+> maybeValueExpr d "where" whr +> where +> sc (Set tg v) = names tg <+> text "=" <+> valueExpr d v +> sc (SetMultiple ts vs) = parens (commaSep $ map names ts) <+> text "=" +> <+> parens (commaSep $ map (valueExpr d) vs) + +== access control + +== transactions + +== sessions + + +== extras + +> dropBehav :: DropBehaviour -> Doc +> dropBehav DefaultDropBehaviour = empty +> dropBehav Cascade = text "cascade" +> dropBehav Restrict = text "restrict" + + = utils > commaSep :: [Doc] -> Doc diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index c1e076b..b9d1adf 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -30,9 +30,15 @@ > ,TableRef(..) > ,JoinType(..) > ,JoinCondition(..) -> -- * dialect +> -- * Statements +> ,Statement(..) +> ,DropBehaviour(..) +> ,IdentityRestart(..) +> ,InsertSource(..) +> ,SetClause(..) +> -- * Dialect > ,Dialect(..) -> -- * comment +> -- * Comment > ,Comment(..) > ) where @@ -380,6 +386,107 @@ I'm not sure if this is valid syntax or not. > | JoinUsing [Name] -- ^ using (column list) > deriving (Eq,Show,Read,Data,Typeable) +--------------------------- + +> data Statement = +> -- ddl +> CreateSchema [Name] -- XXX +> | DropSchema [Name] DropBehaviour -- XXX +> {- | CreateTable -- XXX +> | AlterTable -- XXX +> | DropTable -- XXX +> | CreateView -- XXX +> | DropView -- XXX +> | CreateDomain -- XXX +> | AlterDomain +> | DropDomain -- XXX +> | CreateCharacterSet +> | DropCharacterSet +> | CreateCollation +> | DropCollation +> | CreateTranslation +> | DropTranslation +> | CreateAssertion +> | DropAssertion +> | CreateTrigger +> | DropTrigger +> | CreateType +> | AlterType +> | DropType +> -- routine stuff? +> | CreateCast +> | DropCast +> | CreateOrdering +> | DropOrdering +> -- transforms +> | CreateSequence -- XXX +> | AlterSequence -- XXX +> | DropSequence -- XXX -} +> -- dml +> | SelectStatement QueryExpr +> {- | DeclareCursor +> | OpenCursor +> | FetchCursor +> | CloseCursor +> | SelectInto -} +> -- | DeletePositioned +> | Delete [Name] (Maybe Name) (Maybe ValueExpr) +> | Truncate [Name] IdentityRestart +> | Insert [Name] (Maybe [Name]) InsertSource +> -- | Merge +> | Update [Name] (Maybe Name) [SetClause] (Maybe ValueExpr) +> {- | TemporaryTable +> | FreeLocator +> | HoldLocator -} +> -- access control +> {- | GrantPrivilege +> | GrantRole +> | CreateRole +> | DropRole +> | RevokePrivilege +> | RevokeRole -} +> -- transaction management +> {- | StartTransaction +> | SetTransaction +> | SetContraints +> | SavePoint +> | ReleaseSavePoint +> | Rollback -} +> -- session +> {- | SetSessionCharacteristics +> | SetSessionAuthorization +> | SetRole +> | SetTimeZone +> | SetCatalog +> | SetSchema +> | SetNames +> | SetTransform +> | SetCollation -} +> deriving (Eq,Show,Read,Data,Typeable) + +> data DropBehaviour = +> Restrict +> | Cascade +> | DefaultDropBehaviour +> deriving (Eq,Show,Read,Data,Typeable) + +> data IdentityRestart = +> ContinueIdentity +> | RestartIdentity +> | DefaultIdentityRestart +> deriving (Eq,Show,Read,Data,Typeable) + +> data InsertSource = +> InsertQuery QueryExpr +> | DefaultInsertValues +> deriving (Eq,Show,Read,Data,Typeable) + +> data SetClause = +> Set [Name] ValueExpr +> | SetMultiple [[Name]] [ValueExpr] +> deriving (Eq,Show,Read,Data,Typeable) + +-------------------------- > -- | Used to set the dialect used for parsing and pretty printing, > -- very unfinished at the moment. @@ -388,7 +495,8 @@ I'm not sure if this is valid syntax or not. > deriving (Eq,Show,Read,Data,Typeable) -> -- | Comment. Useful when generating SQL code programmatically. +> -- | Comment. Useful when generating SQL code programmatically. The +> -- parser doesn't produce these. > data Comment = BlockComment String > deriving (Eq,Show,Read,Data,Typeable) diff --git a/simple-sql-parser.cabal b/simple-sql-parser.cabal index ea9d9f2..bd30a22 100644 --- a/simple-sql-parser.cabal +++ b/simple-sql-parser.cabal @@ -4,9 +4,8 @@ synopsis: A parser for SQL. description: A parser for SQL. Parses most SQL:2011 queries, DML, schema/DDL, transaction control, - session and connection management, access - control. Please see the homepage for more - information + session and access control. Please see the + homepage for more information . homepage: http://jakewheat.github.io/simple-sql-parser/ diff --git a/tools/Language/SQL/SimpleSQL/QueryExprs.lhs b/tools/Language/SQL/SimpleSQL/QueryExprs.lhs index 3c62a3b..f7eaf4d 100644 --- a/tools/Language/SQL/SimpleSQL/QueryExprs.lhs +++ b/tools/Language/SQL/SimpleSQL/QueryExprs.lhs @@ -8,11 +8,11 @@ query expressions from one string. > import Language.SQL.SimpleSQL.Syntax > queryExprsTests :: TestItem -> queryExprsTests = Group "query exprs" $ map (uncurry (TestQueryExprs SQL2011)) +> queryExprsTests = Group "query exprs" $ map (uncurry (TestStatements SQL2011)) > [("select 1",[ms]) > ,("select 1;",[ms]) > ,("select 1;select 1",[ms,ms]) > ,(" select 1;select 1; ",[ms,ms]) > ] > where -> ms = makeSelect {qeSelectList = [(NumLit "1",Nothing)]} +> ms = SelectStatement $ makeSelect {qeSelectList = [(NumLit "1",Nothing)]} diff --git a/tools/Language/SQL/SimpleSQL/SQL2011AccessControl.lhs b/tools/Language/SQL/SimpleSQL/SQL2011AccessControl.lhs index f443d81..463b423 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011AccessControl.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011AccessControl.lhs @@ -10,3 +10,110 @@ grant, etc > sql2011AccessControlTests :: TestItem > sql2011AccessControlTests = Group "sql 2011 access control tests" [] + +12 Access control + +12.1 + + ::= + + | + +12.2 + + ::= + GRANT TO [ { }... ] + [ WITH HIERARCHY OPTION ] + [ WITH GRANT OPTION ] + [ GRANTED BY ] + +12.3 + ::= + ON + + ::= + [ TABLE ] + | DOMAIN + | COLLATION + | CHARACTER SET + | TRANSLATION + | TYPE + | SEQUENCE + | + + ::= + ALL PRIVILEGES + | [ { }... ] + + ::= + SELECT + | SELECT + | SELECT + | DELETE + | INSERT [ ] + | UPDATE [ ] + | REFERENCES [ ] + | USAGE + | TRIGGER + | UNDER + | EXECUTE + + ::= + [ { }... ] + + ::= + + + ::= + PUBLIC + | + + ::= + CURRENT_USER + | CURRENT_ROLE + +12.4 + + ::= + CREATE ROLE [ WITH ADMIN ] + +12.5 + + ::= + GRANT [ { }... ] + TO [ { }... ] + [ WITH ADMIN OPTION ] + [ GRANTED BY ] + + ::= + + +12.6 + + ::= + DROP ROLE + +12.7 + + ::= + + | + + ::= + REVOKE [ ] + FROM [ { }... ] + [ GRANTED BY ] + + + ::= + GRANT OPTION FOR + | HIERARCHY OPTION FOR + + ::= + REVOKE [ ADMIN OPTION FOR ] [ { }... ] + FROM [ { }... ] + [ GRANTED BY ] + + + ::= + diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Bits.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Bits.lhs index e3bc18f..541193e 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Bits.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Bits.lhs @@ -1,9 +1,8 @@ -Sections 16, 17, 18 and 19 in Foundation +Sections 17 and 19 in Foundation -This module covers the tests for control statements (call and return), -transaction management (begin, commit, savepoint, etc.), connection -management, and session management (set). +This module covers the tests for transaction management (begin, +commit, savepoint, etc.), and session management (set). > module Language.SQL.SimpleSQL.SQL2011Bits (sql2011BitsTests) where @@ -13,3 +12,170 @@ management, and session management (set). > sql2011BitsTests :: TestItem > sql2011BitsTests = Group "sql 2011 bits tests" [] +17 Transaction management + +17.1 + + ::= + START TRANSACTION [ ] + +BEGIN is not in the standard! + +17.2 + + ::= + SET [ LOCAL ] TRANSACTION + +17.3 + + ::= + [ [ { }... ] ] + + ::= + + | + | + + ::= + READ ONLY + | READ WRITE + + ::= + ISOLATION LEVEL + + ::= + READ UNCOMMITTED + | READ COMMITTED + | REPEATABLE READ + | SERIALIZABLE + + ::= + DIAGNOSTICS SIZE + + ::= + + +17.4 + + ::= + SET CONSTRAINTS { DEFERRED | IMMEDIATE } + + ::= + ALL + | [ { }... ] + +17.5 + + ::= + SAVEPOINT + + ::= + + +17.6 + + ::= + RELEASE SAVEPOINT + +17.7 + + ::= + COMMIT [ WORK ] [ AND [ NO ] CHAIN ] + +17.8 + + ::= + ROLLBACK [ WORK ] [ AND [ NO ] CHAIN ] [ ] + + ::= + TO SAVEPOINT + + +19 Session management + +19.1 + + ::= + SET SESSION CHARACTERISTICS AS + + ::= + [ { }... ] + + ::= + + + ::= + TRANSACTION [ { }... ] + +19.2 + + ::= + SET SESSION AUTHORIZATION + +19.3 + + ::= + SET ROLE + + ::= + + | NONE + +19.4 + + ::= + SET TIME ZONE + + ::= + + | LOCAL + +19.5 + + ::= + SET + + ::= + CATALOG + +19.6 + + ::= + SET + + ::= + SCHEMA + +19.7 + + ::= + SET + + ::= + NAMES + +19.8 + + ::= + SET + + ::= + PATH + +19.9 + + ::= + SET + + ::= + DEFAULT TRANSFORM GROUP + | TRANSFORM GROUP FOR TYPE + +19.10 + + ::= + SET COLLATION [ FOR ] + | SET NO COLLATION [ FOR ] + + ::= + diff --git a/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.lhs b/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.lhs index 17aeb05..bacadd5 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.lhs @@ -5,9 +5,11 @@ Section 14 in Foundation > module Language.SQL.SimpleSQL.SQL2011DataManipulation (sql2011DataManipulationTests) where > import Language.SQL.SimpleSQL.TestTypes +> import Language.SQL.SimpleSQL.Syntax > sql2011DataManipulationTests :: TestItem -> sql2011DataManipulationTests = Group "sql 2011 data manipulation tests" [] +> sql2011DataManipulationTests = Group "sql 2011 data manipulation tests" +> [ 14 Data manipulation @@ -15,72 +17,12 @@ Section 14 in Foundation 14.1 -This Subclause is modified by Subclause 12.1, “”, in ISO/IEC 9075-4. - - -Function -Declare a standing cursor. - - -Format ::= DECLARE FOR - -Syntax Rules -1)  04  If a is contained in an M, then: - a) The shall not be equivalent to the of any other , - , or in M. - b) The scope of the is M with the exception of any contained - in M. - c) Any contained in the shall be defined in a in the that contains an that - specifies the and is contained in the scope of that . - NOTE 463 — See the Syntax Rules of Subclause 13.1, “”. - - -Access Rules - None. - - -General Rules -1) A cursor declaration descriptor CDD is created. CDD includes indications that: - a) The kind of cursor is a standing cursor. - b)  04  The provenance of the cursor is an indication of the SQL-client module whose contains the . - - - Data manipulation 929 - IWD 9075-2:201?(E) -14.1 - - c) The name of the cursor is the . - d) The cursor's origin is the contained in the . - e) The cursor's declared properties are as determined by the . - - -Conformance Rules -1) Without Feature F831, “Full cursor update”, conforming SQL language shall not contain a - that contains both a that contains an that specifies FOR - UPDATE and that contain a . - - - - -930 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.2 - - 14.2 -Function -Specify the declared properties of a cursor. - - -Format ::= [ ] [ ] CURSOR [ ] @@ -103,241 +45,22 @@ Format WITH RETURN | WITHOUT RETURN - -Syntax Rules -1) If is not specified, then ASENSITIVE is implicit. -2) If is not specified, then NO SCROLL is implicit. -3) If is not specified, then WITHOUT HOLD is implicit. -4) If is not specified, then WITHOUT RETURN is implicit. - - -Access Rules - None. - - -General Rules -1) The declared properties of the cursor declaration descriptor associated with are given - by: - a) The declared sensitivity property is the explicit or implicit . - b) The declared scrollability property is the explicit or implicit . - - - Data manipulation 931 - IWD 9075-2:201?(E) -14.2 - - c) The declared holdability property is the explicit or implicit . - d) The declared returnability property is the explicit or implicit . - - -Conformance Rules -1) Without Feature T231, “Sensitive cursors”, conforming SQL language shall not contain a - that immediately contains SENSITIVE. -2) Without Feature F791, “Insensitive cursors”, conforming SQL language shall not contain a that immediately contains INSENSITIVE. -3) Without Feature F791, “Insensitive cursors”, or Feature T231, “Sensitive cursors”, conforming SQL language - shall not contain a that immediately contains ASENSITIVE. -4) Without Feature F431, “Read-only scrollable cursors”, conforming SQL language shall not contain a - . -5) Without Feature T471, “Result sets return value”, conforming SQL language shall not contain a . -6) Without Feature T551, “Optional key words for default syntax”, conforming SQL language shall not contain - a that immediately contains WITHOUT HOLD. - - - - -932 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.3 - - 14.3 -Function -Define a result set. - - -Format ::= [ ] ::= FOR { READ ONLY | UPDATE [ OF ] } - -Syntax Rules -1) Let CS be the . -2) Let QE be the immediately contained in CS. -3) Case: - a) If CS is contained in a DC that contains a , then let CP be that - . - b) If CS is a being prepared by a or re-prepared by an - or a , then: - i) Let STMT be the that is preparing CS, or the or that is re-preparing CS. Let SCMD be the - that contains STMT. - ii) Case: - 1) If CS is being prepared by a , then let PS be that . - 2) Otherwise, let PS be the that previously prepared CS. - iii) Let SSV be the contained in PS. - iv) Case: - 1) If CS is being prepared by a , then: - Case: - A) If SSV is a and there is exactly one DDC - contained in SCMD whose is equivalent to SSV, then let CP1 be - the contained in DDC. - B) If SSV is an that specifies or implies a - that is LOCAL, and there is exactly one - ACS contained in SCMD whose specifies or implies - LOCAL, then let CP1 be the contained in ACS. - - - Data manipulation 933 - IWD 9075-2:201?(E) -14.3 - - C) Otherwise, let CP1 be a zero-length string. - 2) If CS is being re-prepared by an ACS, then - let CP1 be the contained in ACS. - 3) If CS is being re-prepared by a , then let DDC be the whose is equivalent to the contained in - STMT. Let CP1 be the contained in DDC. - v) If PS contains an , then let CP2 be the value of that ; - otherwise, let CP2 be the zero-length string. - vi) Case: - 1) If CP2 contains , then let SENS be that . - 2) If CP1 contains , then let SENS be that . - 3) Otherwise, let SENS be the zero-length string. - vii) Case: - 1) If CP2 contains , then let SCRO be that . - 2) If CP1 contains , then let SCRO be that . - 3) Otherwise, let SCRO be the zero-length string. - viii) Case: - 1) If CP2 contains , then let HOLD be that . - 2) If CP1 contains , then let HOLD be that . - 3) Otherwise, let HOLD be the zero-length string. - ix) Case: - 1) If CP2 contains , then let RET be that . - 2) If CP1 contains , then let RET be that . - 3) Otherwise, let RET be the zero-length string. - x) Let CP be the : - - SENS SCRO CURSOR HOLD RET - -4) If is not specified and either CS is contained in a or is being re- - prepared by an or a , then - Case: - a) If CP contains INSENSITIVE or SCROLL, or QE immediately contains an , or QE - is not a simply updatable , then an of READ ONLY is - implicit. - b) Otherwise, an of FOR UPDATE without a is implicit. - - - -934 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.3 - - NOTE 464 — If CS is being prepared by a , then defaulting the is postponed until - CS is re-prepared. - -5) If an of FOR UPDATE with or without a is specified, then CP - shall not contain INSENSITIVE, QE shall be updatable, and QE shall have only one leaf underlying table - LUT such that QE is one-to-one with respect to LUT. -6) Case: - a) If an specifying FOR UPDATE is specified or implicit, then CS is updatable. - b) If an specifying FOR READ ONLY is specified or implicit, then CS is not - updatable. - c) Otherwise, the determination of updatability of CS is postponed until CS is re-prepared. -7) If CS is updatable, then let LUTN be a
that references LUT. LUTN is an exposed
whose scope is . -8) If an of FOR UPDATE without a is specified or implicit, then - a that consists of the of every column of LUT is implicit. -9) If an of FOR UPDATE with a is specified, then each in the shall be the of a column of LUT. - - -Access Rules - None. - - -General Rules - None. - - -Conformance Rules -1) Without Feature F831, “Full cursor update”, conforming SQL language shall not contain a that contains both an that specifies FOR UPDATE and an . -2) Without Feature T111, “Updatable joins, unions, and columns”, in conforming SQL language, if FOR - UPDATE is specified, then QE shall be simply updatable. - - - - - Data manipulation 935 - IWD 9075-2:201?(E) 14.4 - -14.4 - -This Subclause is modified by Subclause 12.2, “”, in ISO/IEC 9075-4. - - -Function -Open a standing cursor. - - -Format ::= OPEN - -Syntax Rules -1)  04  Let CN be the in the . CN shall be contained within the scope of a - - that is equivalent to CN. -2) CN shall identify a standing cursor. -3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. - - -Access Rules -1) The Access Rules for the simply contained in the identified by the - are applied. - - -General Rules -1) Let CR be the cursor instance descriptor in the current SQL-session whose cursor declaration descriptor - is CDD. -2) The General Rules of Subclause 15.1, “Effect of opening a cursor”, are applied with CR as CURSOR. - - -Conformance Rules - None. - - - - -936 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.5 - - 14.5 -This Subclause is modified by Subclause 12.3, “”, in ISO/IEC 9075-4. -This Subclause is modified by Subclause 11.15, “”, in ISO/IEC 9075-10. -This Subclause is modified by Subclause 14.1, “”, in ISO/IEC 9075-14. - - -Function -Position a standing cursor on a specified row of the standing cursor's result set and retrieve values from that -row. - - -Format - 10  ::= + ::= FETCH [ [ ] FROM ] INTO ::= @@ -347,423 +70,28 @@ Format | LAST | { ABSOLUTE | RELATIVE } - 14  ::= + ::= [ { }... ] -Syntax Rules -1) shall not contain a that specifies a . -2) If the is omitted, then NEXT is implicit. -3)  04   10  Let CN be the in the . CN shall be contained within the scope of a - - that is equivalent to CN. -4) CN shall identify a standing cursor. -5) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. -6) Let T be the result set defined by the of CDD. -7) If the implicit or explicit is not NEXT, then the declared scrollability property of CDD - shall be SCROLL. -8) If a that contains a is specified, then the declared type of - that shall be exact numeric with a scale of 0 (zero). -9) Case: - a) If the contains a single TS and the degree of T is greater than - 1 (one), then the declared type of TS shall be a row type. - Case: - - - - Data manipulation 937 - IWD 9075-2:201?(E) -14.5 - - i)  04  If TS is an , then the Syntax Rules of Subclause 9.2, “Store - - assignment”, are applied with TS as TARGET and an arbitrary value of the row type of T as - VALUE. - ii) Otherwise, the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as - TARGET and an arbitrary value of the row type of T as VALUE. - b) Otherwise: - i) The number of s NTS in the shall be the same as the - degree of T. The i-th , 1 (one) ≤ i ≤ NTS, in the corre- - sponds with the i-th column of T. - ii) For i varying from 1 (one) to NTS, let CSi be an arbitrary value of the declared type of the i-th - column of T. - iii)  04  For each TS1i, 1 (one) ≤ i ≤ NTS, that is either an or a , - Case: - 1) If TS1i contains a , then the Syntax Rules of Subclause 9.2, - “Store assignment”, are applied with an arbitrary site whose declared type is the declared - type of TS1i as TARGET and CSi as VALUE. - - 2) Otherwise, the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with TS1i - as TARGET and CSi as VALUE. - - iv)  10  For each TS2i, 1 (one) ≤ i ≤ NTS, that is a , the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS2i as - TARGET and CSi as VALUE. - - v) For each TS2i, 1 (one) ≤ i, ≤ NTS, that is an , the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS2i as - TARGET and CSi as VALUE. - - -Access Rules - None. - - -General Rules -1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor - is CDD. -2) If CR is not in the open state, then an exception condition is raised: invalid cursor state. -3) The General Rules of Subclause 15.3, “Determination of the current row of a cursor”, are applied with CR - as CURSOR and as FETCH ORIENTATION. -4) If a completion condition no data has been raised, then no further General Rules of this Subclause are - applied. - - -938 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.5 - -5) Case: - a) If the contains a single TS and the degree of T is greater than - 1 (one), then the current row is assigned to TS and - Case: - i)  04   14  If TS is an , then the General Rules of Subclause 9.2, “Store - - assignment”, are applied with TS as TARGET and the current row as VALUE. - ii) Otherwise, the General Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as - TARGET and the current row as VALUE. - b)  10  Otherwise, if the contains more than one , then values from - - the current row are assigned to their corresponding targets identified by the . The - assignments are made in an implementation-dependent order. Let TV be a target and let SV denote its - corresponding value in the current row of CR. - Case: - i)  04  If TV is either an or a , then - - for each in the , let TVi be the i-th - in the and let SVi denote the i-th corresponding value in the current row of - CR. - Case: - 1) If is specified, then - Case: - A) If the value of TVi is the null value, then an exception condition is raised: data - exception — null value in array target. - B) Otherwise: - I) Let N be the maximum cardinality of TVi. - - II) Let M be the cardinality of the value of TVi. - - III) Let I be the value of the immediately contained - in TVi. - - IV) Let EDT be the element type of TVi. - - V) Case: - 1) If I is greater than zero and less than or equal to M, then the value of TVi - is replaced by an array A with element type EDT and cardinality M derived - as follows: - a) For j varying from 1 (one) to I–1 and from I+1 to M, the j-th element - in A is the value of the j-th element in TVi. - - b)  14  The General Rules of Subclause 9.2, “Store assignment”, are applied - - with I-th element of A as TARGET and SVi as VALUE. - - - - Data manipulation 939 - IWD 9075-2:201?(E) -14.5 - - 2) If I is greater than M and less than or equal to N, then the value of TVi is - replaced by an array A with element type EDT and cardinality I derived - as follows: - a) For j varying from 1 (one) to M, the j-th element in A is the value of - the j-th element in TVi. - - b) For j varying from M+1 to I, the j-th element in A is the null value. - c)  14  The General Rules of Subclause 9.2, “Store assignment”, are applied - - with I-th element of A as TARGET and SVi as VALUE. - - 3) Otherwise, an exception condition is raised: data exception — array element - error. - 2)  14  Otherwise, the General Rules of Subclause 9.2, “Store assignment”, are applied with - - TVi as TARGET and SVi as VALUE. - - ii) If TV is a , then the General Rules of Subclause 9.1, “Retrieval assign- - ment”, are applied with TV as TARGET and SV as VALUE. - iii) If TV is an , then the General Rules of Subclause 9.1, - “Retrieval assignment”, are applied with TV as TARGET and SV as VALUE. - NOTE 465 — SQL parameters cannot have as their data types any row type. - -6) If an exception condition occurs during the assignment of a value to a target, then the values of all targets - are implementation-dependent. - NOTE 466 — It is implementation-dependent whether CR remains positioned on the current row when an exception condition - is raised during the derivation of any . - - -Conformance Rules -1) Without Feature F431, “Read-only scrollable cursors”, in conforming SQL language, a - shall not contain a . - - - - -940 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.6 - - 14.6 -This Subclause is modified by Subclause 12.4, “”, in ISO/IEC 9075-4. - - -Function -Close a standing cursor. - - -Format ::= CLOSE - -Syntax Rules -1)  04  Let CN be the in the . CN shall be contained within the scope of a - - that is equivalent to CN. -2) CN shall identify a standing cursor. -3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. - - -Access Rules - None. - - -General Rules -1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor - is CDD. -2) The General Rules of Subclause 15.4, “Effect of closing a cursor”, are applied with CR as CURSOR and - DESTROY as DISPOSITION. - - -Conformance Rules - None. - - - - - Data manipulation 941 - IWD 9075-2:201?(E) 14.7 - -This Subclause is modified by Subclause 12.5, “”, in ISO/IEC 9075-10. -This Subclause is modified by Subclause 14.2, “ ::= SELECT [ ]
- 14  ::= [ { }... ] - -Syntax Rules -1)
. -3) Case: - a) If the shall be the same as the number of elements - in the corresponds with the i-th element of the that is either an or a , - and let SLi be the i-th element of the . - Case: - - - -942 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.7 as VALUE. - iii) For each TS2i, 1 (one) ≤ i ≤ NOE, that is a , - the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS2i as TARGET - and corresponding element of the as VALUE. - -4) Let S be a whose
are those specified in the - . S shall be a valid . -5) A column in the result of the is possibly non-deterministic if S is possibly non-deterministic. - - -Access Rules - None. - - -General Rules -1) Let Q be the result of S. -2) Case: - a) If the cardinality of Q is greater than 1 (one), then an exception condition is raised: cardinality violation. - It is implementation-dependent whether or not SQL-data values are assigned to the targets identified - by the , and a completion condition is raised: no data. - c) Otherwise, values in the row of Q are assigned to their corresponding targets. -3) If a completion condition no data has been raised, then no further General Rules of this Subclause are - applied. -4) Case: - a) If the - - i)  14  If TS is an , then the General Rules of Subclause 9.2, “Store - - assignment”, are applied with TS as TARGET and the current row as VALUE. - ii) Otherwise, the General Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as - TARGET and the current row as VALUE. - b) Otherwise: - i) Let NOE be the number of elements in the that is either an or a , - and let SLi denote the corresponding (i-th) value in the row of Q. The assignment of values to - targets in the - - c)  14  The General Rules of Subclause 9.2, “Store assignment”, are applied - - with I-th element of A as TARGET and SLi as VALUE. - - 3) Otherwise, an exception condition is raised: data exception — array element - error. - 2)  14  Otherwise, the General Rules of Subclause 9.2, “Store assignment”, are applied with - - TSi as TARGET and corresponding value SLi in the row of Q as VALUE. - - iii) For each TS that is a , the General Rules - of Subclause 9.1, “Retrieval assignment”, are applied with TS as TARGET and the corresponding - value in the row of Q as VALUE. The assignment of values to targets in the is in an implementation-dependent order. -5) If an exception condition is raised during the assignment of a value to a target, then the values of all targets - are implementation-dependent. - - -Conformance Rules - None. - - - - - Data manipulation 945 - IWD 9075-2:201?(E) 14.8 - -14.8 - -This Subclause is modified by Subclause 12.6, “”, in ISO/IEC 9075-4. -This Subclause is modified by Subclause 11.12, “”, in ISO/IEC 9075-10. - - -Function -Delete a row of a table. - - -Format - 10  ::= + ::= DELETE FROM [ [ AS ] ] WHERE CURRENT OF @@ -771,235 +99,32 @@ Format
| ONLY
- -Syntax Rules -1)  04  Let DSP be the and let CN be the immediately contained - - in DSP. CN shall be contained within the scope of a that is equivalent to CN. -2) CN shall identify a standing cursor. -3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. -4) The cursor specification of CDD shall be updatable. -5) Let TU be the simply underlying table of the cursor identified by CN. Let LUT be the leaf underlying table - of TU such that TU is one-to-one with respect to LUT. -6) Let TT be the and let TN be the
contained in TT. TN shall identify LUT. -7) LUT shall not be an old transition table or a new transition table. -8) If TT immediately contains ONLY and LUT is not a typed table, then TT is equivalent to TN. -9) TT shall specify ONLY if and only if the
contained in TU that references LUT specifies - ONLY. -10) The schema identified by the explicit or implicit qualifier of TN shall include the descriptor of LUT. -11) Case: - a) If is specified, then let COR be that . COR is an exposed - . - b) Otherwise, let COR be TN. COR is an exposed
. - NOTE 467 — CN has no scope. - - - - -946 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.8 - - -Access Rules -1) Case: - a) If DSP is contained, without an intervening that specifies SQL SECURITY - INVOKER, in an , then let A be the authorization identifier that owns that - schema. The applicable privileges for A shall include DELETE for the table identified by TN. - b) Otherwise, the current privileges shall include DELETE for the table identified by TN. - - -General Rules -1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor - is CDD. -2) The General Rules of Subclause 15.5, “Effect of a positioned delete”, are applied with CR as CURSOR, - DSP as STATEMENT, and TT as TARGET. - - -Conformance Rules -1) Without Feature S111, “ONLY in query expressions”, conforming SQL language shall not contain a - that contains ONLY. - - - - - Data manipulation 947 - IWD 9075-2:201?(E) 14.9 - -14.9 - -This Subclause is modified by Subclause 14.3, “”, in ISO/IEC 9075-14. - - -Function -Delete rows of a table. - - -Format - 14  ::= + ::= DELETE FROM [ FOR PORTION OF FROM TO ] [ [ AS ] ] [ WHERE ] +> (TestStatement SQL2011 "delete from t" +> $ Delete [Name "t"] Nothing Nothing) -Syntax Rules -1) Let DSS be the and let TT be the . -2) Let TN be the
contained in TT. Let T be the table identified by TN. -3) T shall be an updatable table or a trigger deletable table. -4) T shall not be an old transition table or a new transition table. -5) If WHERE is not specified, then WHERE TRUE is implicit. -6) Let DSC be the implicit or explicit . DSC shall not generally contain a whose subject routine is an SQL-invoked routine that possibly modifies SQL-data. - Case: - a) If T is a system-versioned table, then let ENDCOL be the system-time period end column of T. Let - ENDVAL be the highest value supported by the declared type of ENDCOL. Let TSC be +> ,(TestStatement SQL2011 "delete from t as u" +> $ Delete [Name "t"] (Just (Name "u")) Nothing) - ( DSC ) AND ( ENDCOL = ENDVAL ) - - b) Otherwise, let TSC be DSC. -7) Case: - a) If FOR PORTION OF ATPN is specified, then the table descriptor - of T shall include a period descriptor whose period name is equivalent to ATPN. - i) Let BSTARTCOL be the name of the ATPN period start column of T; let BENDCOL be the - name of the ATPN period end column of T. - ii) Let FROMVAL be . FROMVAL shall not generally contain a reference to a - column of T or a whose subject routine is an SQL-invoked routine that - is possibly non-deterministic or that possibly modifies SQL-data. +> ,(TestStatement SQL2011 "delete from t where x = 5" +> $ Delete [Name "t"] Nothing +> (Just $ BinOp (Iden [Name "x"]) [Name "="] (NumLit "5"))) - -948 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.9 - - iii) Let TOVAL be . TOVAL shall not generally contain a reference to a column - of T or a whose subject routine is an SQL-invoked routine that is possibly - nondeterministic or that possibly modifies SQL-data. - iv) Let SC be - - TSC AND - (FROMVAL < TOVAL) AND - (BENDCOL > FROMVAL) AND - (BSTARTCOL < TOVAL) - - b) Otherwise, let SC be TSC. -8) If DSS is contained in a , then SC shall not contain a that - specifies a parameter reference. -9) Case: - a) If is specified, then let CN be that . CN is an exposed . - b) Otherwise, let CN be TN. CN is an exposed
. -10) The scope of CN is SC. - - -Access Rules -1) Case: - a) If DSS is contained, without an intervening that specifies SQL SECURITY - INVOKER, in an , then let A be the that owns - that schema. - i) The applicable privileges for A shall include DELETE for T. - ii) If TT immediately contains ONLY, then the applicable privileges for A shall include SELECT - WITH HIERARCHY OPTION on at least one supertable of T. - b) Otherwise, - i) The current privileges shall include DELETE for T. - ii) If TT immediately contains ONLY, then the current privileges shall include SELECT WITH - HIERARCHY OPTION on at least one supertable of T. - - -General Rules -1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch - of the current SQL-transaction at the current SQL-connection is read-only, and T is not a temporary table, - then an exception condition is raised: invalid transaction state — read-only SQL-transaction. -2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement - is being executed, then - Case: - - - Data manipulation 949 - IWD 9075-2:201?(E) -14.9 - - a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the - successful execution of this statement shall be made visible to CR or an exception condition is raised: - cursor sensitivity exception — request failed. - b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made - visible to CR is implementation-defined. -3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution - of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception - — request failed. -4) The extent to which an SQL-implementation may disallow independent changes that are not significant is - implementation-defined. -5) SC is effectively evaluated for each row of T with the exposed s or
s bound to that row. -6) Case: - a) If TT contains ONLY, then the rows for which the result of SC is True and for which there is no subrow - in a proper subtable of T are identified for deletion from T. - b) Otherwise, the rows for which the result of SC is True are identified for deletion from T. - NOTE 468 — Identifying a row for deletion is an implementation-dependent mechanism. - -7) Let S be the set consisting of every row identified for deletion from T. S is the old delta table of delete - operation on T. If FOR PORTION OF is specified, then FROMVAL and TOVAL are associated with every - row in S as the associated for portion of from-value and the associated for portion of to-value, respectively. -8) Case: - a) If T is a base table, then: - i) Case: - 1) If TT specifies ONLY, then T is identified for deletion processing without subtables. - 2) Otherwise, T is identified for deletion processing with subtables. - NOTE 469 — Identifying a base table for deletion processing, with or without subtables, is an implementation- - dependent mechanism. - - ii) The General Rules of Subclause 15.7, “Effect of deleting rows from base tables”, are applied. - b) If T is a viewed table, then the General Rules of Subclause 15.9, “Effect of deleting some rows from - a viewed table”, are applied with TT as VIEW NAME. -9) If any row that is marked for deletion by DSS has been marked for deletion by any , , or - that identifies some open cursor CR or updated by any , , or that identifies some open - cursor CR, then a completion condition is raised: warning — cursor operation conflict. -10) If no rows are marked for deletion, then a completion condition is raised: no data. - - - - -950 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.9 - - -Conformance Rules -1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain a in which either of the following is true: - a) A leaf generally underlying table of T is an underlying table of any broadly con- - tained in the . - b) The broadly contains a , , , or whose subject routine is an external routine that possibly reads - SQL-data. -2) Without Feature T111, “Updatable joins, unions, and columns”, conforming SQL language shall not contain - a that contains a that identifies a table that is not simply - updatable. -3) Without Feature T181, “Application-time period tables”, in conforming SQL language, a shall not contain FOR PORTION OF. - - - - - Data manipulation 951 - IWD 9075-2:201?(E) -14.10 - +> ,(TestStatement SQL2011 "delete from t as u where u.x = 5" +> $ Delete [Name "t"] (Just (Name "u")) +> (Just $ BinOp (Iden [Name "u", Name "x"]) [Name "="] (NumLit "5"))) 14.10 -Function -Delete all rows of a base table without causing any triggered action. - - -Format ::= TRUNCATE TABLE [ ] @@ -1007,88 +132,19 @@ Format CONTINUE IDENTITY | RESTART IDENTITY +> ,(TestStatement SQL2011 "truncate table t" +> $ Truncate [Name "t"] DefaultIdentityRestart) -Syntax Rules -1) Let TTS be the and let TT be the contained in TTS. -2) Let TN be the
contained in TT and let T be the table identified by TN. The schema identified - by the explicit or implicit of TN shall include the descriptor of T. -3) T shall be a base table and shall not be a system-versioned table. -4) T shall not be identified by the name of the referenced table in any referential constraint descriptor. -5) If is not specified, then CONTINUE IDENTITY is implicit. +> ,(TestStatement SQL2011 "truncate table t continue identity" +> $ Truncate [Name "t"] ContinueIdentity) - -Access Rules -1) Let A be the that owns the schema identified by the of T. -2) The enabled authorization identifiers shall include A. - - -General Rules -1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch - of the current SQL-transaction at the current SQL-connection is read-only, and T is not a temporary table, - then an exception condition is raised: invalid transaction state — read-only SQL-transaction. -2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement - is being executed, then - Case: - a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the - successful execution of this statement shall be made visible to CR or an exception condition is raised: - cursor sensitivity exception — request failed. - b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made - visible to CR is implementation-defined. - - -952 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.10 - -3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution - of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception - — request failed. -4) The extent to which an SQL-implementation may disallow independent changes that are not significant is - implementation-defined. -5) Case: - a) If TT contains ONLY, then the rows for which there is no subrow in a proper subtable of T are deleted - from T. - b) Otherwise, all rows are deleted from T. -6) If any row that is deleted from T by TTS has been marked for deletion by any , - , or that iden- - tifies some open cursor CR or updated by any , , or that identifies some open cursor CR, - then a completion condition is raised: warning — cursor operation conflict. -7) If no rows are deleted from T, then a completion condition is raised: no data. -8) If RESTART IDENTITY is specified and the table descriptor of T includes a column descriptor IDCD of - an identity column, then: - a) Let CN be the column name included in IDCD and let SV be the start value included in IDCD. - b) The following is effectively executed without further Access Rule checking: - - ALTER TABLE TN ALTER COLUMN CN RESTART WITH SV - - -Conformance Rules -1) Without Feature F200, “TRUNCATE TABLE statement”, conforming SQL language shall not contain a - . -2) Without Feature F202, “TRUNCATE TABLE: identity column restart option”, conforming SQL language - shall not contain an . - - - - - Data manipulation 953 - IWD 9075-2:201?(E) -14.11 +> ,(TestStatement SQL2011 "truncate table t restart identity" +> $ Truncate [Name "t"] RestartIdentity) 14.11 -This Subclause is modified by Subclause 14.4, “”, in ISO/IEC 9075-14. - - -Function -Create new rows in a table. - - -Format - 14  ::= + ::= INSERT INTO ::= @@ -1119,243 +175,42 @@ Format ::= +> ,(TestStatement SQL2011 "insert into t select * from u" +> $ Insert [Name "t"] Nothing +> $ InsertQuery makeSelect +> {qeSelectList = [(Star, Nothing)] +> ,qeFrom = [TRSimple [Name "u"]]}) -Syntax Rules -1) Let IS be the . -2) Let TN be the
contained in . Let T be the table identified by TN. -3) T shall be an insertable-into table or a trigger insertable-into table. -4) T shall not be an old transition table or a new transition table. -5) For each leaf generally underlying table of T whose descriptor includes a user-defined type name UDTN, - the data type descriptor of the user-defined type UDT identified by UDTN shall indicate that UDT is - instantiable. +> ,(TestStatement SQL2011 "insert into t(a,b,c) select * from u" +> $ Insert [Name "t"] (Just [Name "a", Name "b", Name "c"]) +> $ InsertQuery makeSelect +> {qeSelectList = [(Star, Nothing)] +> ,qeFrom = [TRSimple [Name "u"]]}) +> ,(TestStatement SQL2011 "insert into t default values" +> $ Insert [Name "t"] Nothing DefaultInsertValues) -954 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.11 +> ,(TestStatement SQL2011 "insert into t values(1,2)" +> $ Insert [Name "t"] Nothing +> $ InsertQuery $ Values [[NumLit "1", NumLit "2"]]) -6) An that specifies DEFAULT VALUES is implicitly replaced by an that specifies a of the form +> ,(TestStatement SQL2011 "insert into t values (1,2),(3,4)" +> $ Insert [Name "t"] Nothing +> $ InsertQuery $ Values [[NumLit "1", NumLit "2"] +> ,[NumLit "3", NumLit "4"]]) - VALUES (DEFAULT, DEFAULT, ..., DEFAULT) - - where the number of instances of “DEFAULT” equal to the number of columns of T. -7) If the is omitted, then an that identifies all columns of T in the - ascending sequence of their ordinal positions within T is implicit. -8) A column identified by the is an object column. No of T shall be - identified more than once. -9) If T is not trigger insertable-into, then T shall be an updatable table; each object column shall be an - updatable column of T . - NOTE 470 — The notion of updatable columns of base tables is defined in Subclause 4.15, “Tables”. The notion of updatable - columns of viewed tables is defined in Subclause 11.32, “”. - -10) If CTTVC is specified, then every simply contained in CTTVC whose positionally corresponding - in references a column of which some underlying column is a generated column shall - be a . -11) Case: - a) If some underlying column of a column referenced by a contained in is a system-generated self-referencing column or a derived self-referencing column, then shall be specified. - b) If for some n, some underlying column of the column referenced by the CN contained - in the n-th ordinal position in is an identity column, system-time period start - column, or system-time period end column whose descriptor includes an indication that values are - always generated, then - Case: - i) If is specified, then shall be specified. - ii) If any simply contained in the is a , then shall be specified. - iii) If the n-th simply contained in any simply contained in the is not a , then shall be specified. - NOTE 471 — The preceding subrule does not cover all possibilities. The remaining possibilities are where is specified for every identity column, or for a system-time period start column or system-time period - end column, in which case it is immaterial whether is specified or not. - - c) If for some n, some underlying column of the column referenced by the CN contained - in the n-th ordinal position in is an identity column whose descriptor includes an - indication that values are generated by default, then if is specified, then shall specify OVERRIDING USER VALUE. - d) If for some n, some underlying column of the column referenced by the CN contained - in the n-th ordinal position in is a system-time period start column or a system- - - - - Data manipulation 955 - IWD 9075-2:201?(E) -14.11 - - time period end column whose descriptor includes an indication that values are always generated and - is specified, then shall specify OVERRIDING USER VALUE. - e) Otherwise, shall not be specified. -12) If CVC is specified, then the data type of every CVS specified in every CRVS con- - tained in CVC is the data type DT indicated in the column descriptor for the positionally corresponding - column in the explicit or implicit . If CVS is an that specifies - ARRAY, then DT shall be an array type. If CVS is an that specifies MULTISET, - then DT shall be a multiset type. -13) Let QT be the table specified by the or . - The degree of QT shall be equal to the number of s in the . The column - of table T identified by the i-th in the corresponds with the i-th column - of QT. -14) The Syntax Rules of Subclause 9.2, “Store assignment”, are applied with corresponding columns of T as - TARGET and QT as VALUE. -15) If IS is contained in a , then shall not contain a - that specifies a parameter reference. -16) A simply contained in a shall not be a
. - NOTE 472 — This rule removes a syntactic ambiguity; otherwise, “VALUES (1)” could be parsed either as - - ::= - ::= - ::= -
::= - VALUES (1) - - or - - ::= - ::= - ::= - VALUES (1) - - -Access Rules -1) Case: - a) If IS is contained in, without an intervening that specifies SQL SECURITY - INVOKER, an , then let A be the that owns that - schema. The applicable privileges for A for T shall include INSERT for each object column. - b) Otherwise, the current privileges for T shall include INSERT for each object column. - - - - -956 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.11 - - -General Rules -1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch - of the current SQL-transaction at the current SQL-connection is read-only, and T is not a temporary table, - then an exception condition is raised: invalid transaction state — read-only SQL-transaction. -2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement - is being executed, then - Case: - a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the - successful execution of this statement shall be made visible to CR or an exception condition is raised: - cursor sensitivity exception — request failed. - b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made - visible to CR is implementation-defined. -3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution - of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception - — request failed. -4) The extent to which an SQL-implementation may disallow independent changes that are not significant is - implementation-defined. -5) QT is effectively evaluated before insertion of any rows into T. -6) Let Q be the result of evaluating QT. -7) For each row R of Q: - a) A candidate row of T is effectively created in which the value of each column is its default value, as - specified in the General Rules of Subclause 11.5, “”. The candidate row consists of - every column of T. - b) For each object column in the candidate row, let Ci be the object column identified by the i-th in the and let SVi be the i-th value of R. - - c) For every Ci such that Ci is not marked as unassigned and no underlying column of Ci is a self-refer- - encing column, the General Rules of Subclause 9.2, “Store assignment”, are applied with Ci as TARGET - and SVi as VALUE. Ci is no longer marked as unassigned. - - d) If T has a column RC of which some underlying column is a self-referencing column, then - Case: - i) If RC is a system-generated self-referencing column, then the value of RC is effectively replaced - by the REF value of the candidate row. - ii) If RC is a derived self-referencing column, then the value of RC is effectively replaced by a - value derived from the columns in the candidate row that correspond to the list of attributes of - the derived representation of the reference type of RC in an implementation-dependent manner. - e) For every Ci for which one of the following conditions is true: - - i) Some underlying column of Ci is a user-generated self-referencing column. - - - Data manipulation 957 - IWD 9075-2:201?(E) -14.11 - - ii) Some underlying column of Ci is a self-referencing column and OVERRIDING SYSTEM - VALUE is specified. - iii) Some underlying column of Ci is an identity column and the i-th column of R is not derived - from and OVERRIDING SYSTEM VALUE is specified. - iv) Some underlying column of Ci is an identity column whose descriptor includes an indication - that values are generated by default and neither OVERRIDING USER VALUE is specified - nor is the i-th column derived from . - The General Rules of Subclause 9.2, “Store assignment”, are applied with Ci as TARGET and SVi as - VALUE. Ci is no longer marked as unassigned. - NOTE 473 — If OVERRIDING USER VALUE is specified, then some columns of the candidate row(s) may continue to - be marked as unassigned as a result of the preceding rules. The value of such columns is ultimately determined by the General - Rules of Subclause 15.10, “Effect of inserting tables into base tables”, which has the effect of overriding user values specified - in . - NOTE 474 — The data values allowable in the candidate row may be constrained by a WITH CHECK OPTION constraint. - The effect of a WITH CHECK OPTION constraint is defined in the General Rules of Subclause 15.12, “Effect of inserting - a table into a viewed table”. - -8) Let S be the table consisting of the candidate rows. - Case: - a) If T is a base table, then: - i) T is identified for insertion of source table S. - NOTE 475 — Identifying a base table for insertion of a source table is an implementation-dependent operation. - - ii) The General Rules of Subclause 15.10, “Effect of inserting tables into base tables”, are applied. - b) If T is a viewed table, then the General Rules of Subclause 15.12, “Effect of inserting a table into a - viewed table”, are applied with S as SOURCE and T as TARGET. -9) If Q is empty, then a completion condition is raised: no data. - - -Conformance Rules -1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain an - in which either of the following is true: - a) The
of a leaf generally underlying table of T is broadly contained in the - except as the table name of a qualifying table of a column reference. - b) The broadly contains a , , , or whose subject routine is an external routine that possibly reads - SQL-data. -2) Without Feature F222, “INSERT statement: DEFAULT VALUES clause”, conforming SQL language - shall not contain a . -3) Without Feature S024, “Enhanced structured types”, in conforming SQL language, for each column C - identified in the explicit or implicit , if the declared type of C is a structured type TY, - - - - -958 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.11 - - then the declared type of the corresponding column of the or shall be TY. -4) Without Feature S043, “Enhanced reference types”, conforming SQL language shall not contain an - . -5) Without Feature T111, “Updatable joins, unions, and columns”, conforming SQL language shall not contain - an that contains an that identifies a table that is not simply updatable. - - - - - Data manipulation 959 - IWD 9075-2:201?(E) -14.12 +> ,(TestStatement SQL2011 +> "insert into t values (default,null,array[],multiset[])" +> $ Insert [Name "t"] Nothing +> $ InsertQuery $ Values [[Iden [Name "default"] +> ,Iden [Name "null"] +> ,Array (Iden [Name "array"]) [] +> ,MultisetCtor []]]) 14.12 -This Subclause is modified by Subclause 14.5, “”, in ISO/IEC 9075-14. - - -Function -Conditionally update and/or delete rows of a table and/or insert new rows into a table. - - -Format - 14  ::= + ::= MERGE INTO [ [ AS ] ] USING
ON @@ -1402,481 +257,16 @@ Format | - - -960 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.12 - - -Syntax Rules -1) Let TN be the
contained in TT and let T be the table identified by TN. -2) If is specified, then T shall be insertable-into or trigger insertable-into. -3) If is specified, then T shall be updatable or trigger updatable. -4) If is specified, then T shall be updatable or trigger deletable. -5) T shall not be an old transition table or a new transition table. -6) For each leaf generally underlying table of T whose descriptor includes a user-defined type name UDTN, - the data type descriptor of the user-defined type UDT identified by UDTN shall indicate that UDT is - instantiable. -7) If T is a view, then is effectively replaced by: - - ONLY ( TN ) - -8) Case: - a) If is specified, then let CN be the contained in . CN is an exposed . - b) Otherwise, let CN be the
contained in . CN is an exposed
. -9) The scope of CN is the immediately contained in the , the immediately contained in a , the immediately - contained in a , and the . -10) Let TR be the
immediately contained in . TR shall not directly contain - a . -11) The or
that is exposed by TR shall not be equivalent to CN. -12) If an is omitted, then an that identifies all columns of T in the - ascending sequence of their ordinal position within T is implicit. -13) Case: - a) If some underlying column of a column referenced by a contained in is a system-generated self-referencing column or a derived self-referencing column, then shall be specified. - b) If for some n, some underlying column of the column referenced by the contained - in the n-th ordinal position in is an identity column, system-time period start - column, or system-time period end column whose descriptor includes an indication that values are - always generated, and the n-th simply contained in any - simply contained in the is not a , then shall be specified. - c) If for some n, some underlying column of the column referenced by the contained - in the n-th ordinal position in is an identity column whose descriptor includes an - indication that values are generated by default and is specified, then shall specify OVERRIDING USER VALUE. - - - Data manipulation 961 - IWD 9075-2:201?(E) -14.12 - - d) If for some n, some underlying column of the column referenced by the contained - in the n-th ordinal position in is a system-time period start column or a system- - time period end column whose descriptor includes an indication that values are always generated and - is specified, then shall specify OVERRIDING USER VALUE. - e) Otherwise, shall not be specified. -14) The immediately contained in a , the immediately - contained in a , and the immediately contained in a - shall not generally contain a whose subject routine - is an SQL-invoked routine that possibly modifies SQL-data. -15) Each column identified by an in a is an update object column. Each - column identified by a in an implicit or explicit is an insert object - column. Each update object column and each insert object column is an object column. -16) If is specified and if T is not trigger insertable-into or if is specified and if T is not trigger updatable, then every object column shall identify an - updatable column of T. - NOTE 476 — The notion of updatable columns of base tables is defined in Subclause 4.15, “Tables”. The notion of updatable - columns of viewed tables is defined in Subclause 11.32, “”. - -17) No of T shall be identified more than once in an . -18) For each : - a) Let NI be the number of s contained in . Let - EXP1, EXP2, ... , EXPNI be those s. - - b) The number of s in the shall be equal to NI. - c) The declared type of every CVS in a is the data type DT indicated in the column descriptor for the positionally corresponding column - in the explicit or implicit . If CVS is an that specifies - ARRAY, then DT shall be an array type. If CVS is an that specifies MULTISET, - then DT shall be a multiset type. - d) Every whose positionally corresponding in references a column of which some underlying column is a generated column shall be a - . - e) For 1 (one) ≤ i ≤ NI, the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with EXPi - as VALUE and the column of table T identified by the i-th in the - as TARGET. -19) Let DSC be the immediately contained in . - Case: - a) If T is a system-versioned table, then let ENDCOL be the system-time period end column of T. Let - ENDVAL be the highest value supported by the declared type of ENDCOL. Let SC1 be - - (DSC) AND (ENDCOL = ENDVAL) - - b) Otherwise, let SC1 be DSC. - - - -962 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.12 - - -Access Rules -1) Case: - a) If is contained, without an intervening that specifies SQL - SECURITY INVOKER, in an , then let A be the - that owns that schema. - i) If is specified, then the applicable privileges for A shall include - UPDATE for each update object column. - ii) If is specified, then the applicable privileges for A shall include - DELETE for T. - iii) If is specified, then the applicable privileges for A shall include - INSERT for each insert object column. - iv) If TT immediately contains ONLY, then the applicable privileges for A shall include SELECT - WITH HIERARCHY OPTION on at least one supertable of T. - b) Otherwise, - i) If is specified, then the current privileges shall include UPDATE - for each update object column. - ii) If is specified, then the applicable privileges for A shall include - DELETE for T. - iii) If is specified, then the current privileges shall include INSERT - for each insert object column. - iv) If TT immediately contains ONLY, then the current privileges shall include SELECT WITH - HIERARCHY OPTION on at least one supertable of T. - - -General Rules -1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch - of the current SQL-transaction at the current SQL-connection is read-only, and T is not a temporary table, - then an exception condition is raised: invalid transaction state — read-only SQL-transaction. -2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement - is being executed, then - Case: - a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the - successful execution of this statement shall be made visible to CR or an exception condition is raised: - cursor sensitivity exception — request failed. - b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made - visible to CR is implementation-defined. -3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution - of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception - — request failed. - - - Data manipulation 963 - IWD 9075-2:201?(E) -14.12 - -4) The extent to which an SQL-implementation may disallow independent changes that are not significant is - implementation-defined. -5) Let QT be the table specified by the
. QT is effectively evaluated before update, deletion, - or insertion of any rows in T. Let Q be the result of evaluating QT. -6) For each , in the order specified in the , - Case: - a) If MWMC is specified, then: - i) For each row R1 of T: - 1) SC1 and the SC2 immediately contained in MWMC, if any, are effec- - tively evaluated for R1 with the exposed
of the TT bound to R1 and to each - row of Q with the exposed s or
s of the
bound to that row. Both SC1 and SC2 are effectively evaluated for R1 before - updating or deleting any row of T and prior to the invocation of any - caused by the update or deletion of any row of T and before inserting any rows into T and - prior to the invocation of any caused by the insert of any row of T. - Case: - A) If TT contains ONLY, then R1 is a subject row if R1 has no subrow in a proper subtable - of T and the result of both SC1 and SC2 are True for some row R2 of Q and R1 is not - a subject row identified by any other that precedes - MWMC in the . R2 is the matching row. - B) Otherwise, R1 is a subject row if the result of both SC1 and SC2 are True for some - row R2 of Q and R1 is not a subject row identified by any other that precedes MWMC in the . R2 is the - matching row. - 2) If R1 is a subject row, then: - A) Let M be the number of matching rows in Q for R1. - B) If M is greater than 1 (one), then an exception condition is raised: cardinality violation. - C) If is specified, then: - I) The of each is effectively evaluated for R1 before - any row of T is updated and prior to the invocation of any - caused by the update of any row of T. The resulting value is the update value. - II) A candidate new row is constructed by copying the subject row and updating - it as specified by each by applying the General Rules of - Subclause 14.15, “”. - ii) Let S be the set consisting of every subject row. S is the old delta table of merge operation on - T. - iii) If T is a base table, then each subject row is also an object row; otherwise, an object row is any - row of a leaf generally underlying table of T from which a subject row is derived. - - - - -964 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.12 - - NOTE 477 — The data values allowable in the object rows may be constrained by a WITH CHECK OPTION - constraint. The effect of a WITH CHECK OPTION constraint is defined in the General Rules of Subclause 15.15, - “Effect of replacing some rows in a viewed table”. - -iv) If any row in the set of object rows has been marked for deletion by any , , or that identifies some open cursor CR or updated by any , , or that identifies some open cursor, then a completion condition is raised: warning - — cursor operation conflict. -v) If is specified, then: - 1) Let CL be the columns of T identified by the s contained in the . - 2) Each subject row SR is identified for replacement, by its corresponding candidate new row - CNR, in T. The set of (SR, CNR) pairs is the replacement set for T. - NOTE 478 — Identifying a row for replacement, associating a replacement row with an identified row, - and associating a replacement set with a table are implementation-dependent operations. - - 3) Case: - A) If T is a base table, then: - I) Case: - 1) If TT specifies ONLY, then T is identified for replacement processing - without subtables with respect to object columns CL. - 2) Otherwise, T is identified for replacement processing with subtables with - respect to object columns CL. - NOTE 479 — Identifying a base table for replacement processing, with or without - subtables, is an implementation-dependent mechanism. In general, though not here, - the list of object columns can be empty. - - II) The General Rules of Subclause 15.13, “Effect of replacing rows in base tables”, - are applied. - B) If T is a viewed table, then the General Rules of Subclause 15.15, “Effect of replacing - some rows in a viewed table”, are applied with TT as VIEW NAME and the replacement - set for T as REPLACEMENT SET FOR VIEW NAME. -vi) If is specified, then: - 1) Each subject row is identified for deletion from T. - 2) Case: - A) If T is a base table, then: - I) Case: - 1) If TT specifies ONLY, then T is identified for deletion processing without - subtables. - 2) Otherwise, T is identified for deletion processing with subtables. - - - - Data manipulation 965 - IWD 9075-2:201?(E) -14.12 - - NOTE 480 — Identifying a base table for deletion processing, with or without subta- - bles, is an implementation-dependent mechanism. - - II) The General Rules of Subclause 15.7, “Effect of deleting rows from base tables”, - are applied. - B) Otherwise, T is a viewed table and the General Rules of Subclause 15.9, “Effect of - deleting some rows from a viewed table”, are applied with TT as VIEW NAME. - b) If MWNMC is specified, then: - i) Let TR1 be the immediately contained in and let TR2 be the -
immediately contained in . If - is specified, then let MCN be “AS ”; otherwise, let MCN be a zero- - length string. If MWNMC immediately contains a SC2, then let ONSC2 be - “OR NOT SC2”; otherwise, let ONSC2 be a zero-length string. Let S1 be the result of - - SELECT * - FROM TR1 MCN, TR2 - WHERE SC1 ONSC2 - - ii) Let S2 be the collection of rows of Q for which there exists in S1 some row that is the concate- - nation of some row R1 of T and some row R2 of Q. - iii) Let S3 be the collection of rows of Q that are not in S2. Let SN3 be the effective distinct name - for S3. Let EN be the exposed or
of TR2. - iv) Let S4 be the result of: - - SELECT EXP1, EXP2, ... , EXPNI - FROM SN3 AS EN - - v) Let S5 be the collection of rows of S4 for which no candidate rows have been effectively created - by any other that precedes MWNMC in the . - vi) S5 is effectively evaluated before deletion of any rows from, insertion of any rows into, or - update of any rows in T. - vii) For each row R of S5: - 1) A candidate row of T is effectively created in which the value of each column is its default - value, as specified in the General Rules of Subclause 11.5, “”. The candidate - row consists of every column of T. - 2) If T has a column RC of which some underlying column is a self-referencing column, then - Case: - A) If RC is a system-generated self-referencing column, then the value of RC is effectively - replaced by the REF value of the candidate row. - B) If RC is a derived self-referencing column, then the value of RC is effectively replaced - by a value derived from the columns in the candidate row that correspond to the list - of attributes of the derived representation of the reference type of RC in an implemen- - tation-dependent manner. - - - -966 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.12 - - 3) For each object column in the candidate row, let Ci be the object column identified by the - i-th in the and let SVi be the i-th value of R. - - 4) For every Ci for which one of the following conditions is true: - - A) Ci is not marked as unassigned and no underlying column of Ci is a self-referencing - column. - B) Some underlying column of Ci is a user-generated self-referencing column. - - C) Some underlying column of Ci is a self-referencing column and OVERRIDING - SYSTEM VALUE is specified. - D) Some underlying column of Ci is an identity column and the i-th column of R is not - derived from and OVERRIDING SYSTEM VALUE is speci- - fied. - E) Some underlying column of Ci is an identity column whose descriptor includes an - indication that values are generated by default and neither OVERRIDING USER - VALUE is specified nor is the i-th column derived from . - the General Rules of Subclause 9.2, “Store assignment”, are applied with Ci as TARGET - and SVi as VALUE. Ci is no longer marked as unassigned. - NOTE 481 — If OVERRIDING USER VALUE is specified, then some columns of the candidate row(s) - may continue to be marked as unassigned as a result of the preceding rules. The value of such columns - is ultimately determined by the General Rules of Subclause 15.10, “Effect of inserting tables into base - tables”, which has the effect of overriding user values specified in . - NOTE 482 — The data values allowable in the candidate row may be constrained by a WITH CHECK - OPTION constraint. The effect of a WITH CHECK OPTION constraint is defined in the General Rules - of Subclause 15.12, “Effect of inserting a table into a viewed table”. - - viii) Let S be the table consisting of the candidate rows. - Case: - 1) If T is a base table, then: - A) T is identified for insertion of source table S. - NOTE 483 — Identifying a base table for insertion of a source table is an implementation-dependent - operation. - - B) The General Rules of Subclause 15.10, “Effect of inserting tables into base tables”, - are applied. - 2) If T is a viewed table, then the General Rules of Subclause 15.12, “Effect of inserting a - table into a viewed table”, are applied with S as SOURCE and T as TARGET. -7) If Q is empty, then a completion condition is raised: no data. - - -Conformance Rules -1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain a in which either of the following is true: - - - - Data manipulation 967 - IWD 9075-2:201?(E) -14.12 - - a) A leaf generally underlying table of T is broadly contained in a immediately - contained in the
except as the
or of a - column reference. - b) A immediately contained in the
broadly contains a , , , or whose subject - routine is an external routine that possibly reads SQL-data. -2) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain a in which either of the following is true: - a) A leaf generally underlying table of T is an underlying table of any broadly con- - tained in any . - b) Any broadly contains a , , , or whose subject routine is an external routine that possibly reads - SQL-data. -3) Without Feature S024, “Enhanced structured types”, conforming SQL language shall not contain a that does not satisfy the condition: for each column C identified in the explicit or implicit , if the declared type of C is a structured type TY, then the declared type of the corresponding - column of the or is TY. -4) Without Feature F312, “MERGE statement”, conforming SQL language shall not contain a . -5) Without Feature T111, “Updatable joins, unions, and columns”, conforming SQL language shall not contain - a that contains an that identifies a table that is not simply updatable. -6) Without Feature F313, “Enhanced MERGE statement”, in conforming SQL language, a - shall not contain each of and more than - once. -7) Without Feature F313, “Enhanced MERGE statement”, in conforming SQL language, a or a shall not immediately contain a . -8) Without Feature F314, “MERGE statement with DELETE branch”, in conforming SQL language, a shall not immediately contain a . - - - - -968 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.13 - - 14.13 -This Subclause is modified by Subclause 12.7, “”, in ISO/IEC 9075-4. -This Subclause is modified by Subclause 11.13, “”, in ISO/IEC 9075-10. -This Subclause is modified by Subclause 14.6, “”, in ISO/IEC 9075-14. - - -Function -Update a row of a table. - - -Format - 10   14  ::= + ::= UPDATE [ [ AS ] ] SET WHERE CURRENT OF - -Syntax Rules -1)  04  Let USP be the and let CN be the immediately contained - - in USP. CN shall be contained within the scope of a that is equivalent to CN. -2) CN shall identify a standing cursor. -3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. -4) The cursor specification of CDD shall be updatable. -5) Let TU be the simply underlying table of the cursor identified by CN. Let LUT be the leaf underlying table - of TU such that TU is one-to-one with respect to LUT. -6) Let TT be the and let TN be the
contained in TT. TN shall identify LUT. -7) LUT shall not be an old transition table or a new transition table. -8) It TT immediately contains ONLY and LUT is not a typed table, then TT is equivalent to TN. -9) TT shall specify ONLY if and only if the
contained in TU that references LUT specifies - ONLY. -10) The schema identified by the explicit or implicit qualifier of TN shall include the descriptor of LUT. -11) Case: - a) If is specified, then let COR be that . COR is an exposed - . - b) Otherwise, let COR be the
contained in TT. COR is an exposed
. -12) The scope of COR is . -13) If the declared CS of CDD is ordered, then for each OC contained - in , no generally underlying column of a in the simply con- - tained in the of CS shall be OC or a generally underlying column of OC. - - - Data manipulation 969 - IWD 9075-2:201?(E) -14.13 - -14) Each specified as an shall identify a column in the explicit or implicit - contained in the explicit or implicit of the - of CDD. - - -Access Rules -1) Case: - a) If USP is contained, without an intervening that specifies SQL SECURITY - INVOKER, in an , then let A be the that owns - that schema. The applicable privileges for A shall include UPDATE for each . - b) Otherwise, the current privileges shall include UPDATE for each . - - -General Rules -1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor - is CDD. -2) Let SCL be the . -3) The General Rules of Subclause 15.6, “Effect of a positioned update”, are applied with CR as CURSOR, - SCL as SET CLAUSE LIST, USP as STATEMENT, and TT as TARGET. - - -Conformance Rules -1) Without Feature F831, “Full cursor update”, conforming SQL language shall not contain an in which the declared of CDD is ordered. - - - - -970 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.14 - - 14.14 -This Subclause is modified by Subclause 14.7, “”, in ISO/IEC 9075-14. - - -Function -Update rows of a table. - - -Format - 14  ::= + ::= UPDATE [ FOR PORTION OF FROM TO ] @@ -1885,209 +275,37 @@ Format [ WHERE ] -Syntax Rules -1) Let USS be the , let TT be the contained in USS, and let SCL - be the contained in USS. -2) Let TN be the
contained in TT and let T be the table identified by TN. -3) T shall be an updatable table or a trigger updatable table. -4) T shall not be an old transition table or a new transition table. -5) If WHERE is not specified, then WHERE TRUE is implicit. -6) Let DSC be the implicit or explicit . DSC shall not generally contain a whose subject routine is an SQL-invoked routine that possibly modifies SQL-data. - Case: - a) If T is a system-versioned table, then let ENDCOL be the system-time period end column of T. Let - ENDVAL be the highest value supported by the declared type of ENDCOL. Let TSC be +> ,(TestStatement SQL2011 "update t set a=b" +> $ Update [Name "t"] Nothing +> [Set [Name "a"] (Iden [Name "b"])] Nothing) - (DSC) AND (ENDCOL = ENDVAL) - - b) Otherwise, let TSC be DSC. -7) Case: - a) If FOR PORTION OF ATPN is specified, then the table descriptor - of T shall include a ATPN period descriptor. - i) Let BSTARTCOL be the name of the ATPN period start column of T; let BENDCOL be the - name of the ATPN period end column of T. Let BCD be the declared type of the ATPN period - start column of T. +> ,(TestStatement SQL2011 "update t set a=b, c=5" +> $ Update [Name "t"] Nothing +> [Set [Name "a"] (Iden [Name "b"]) +> ,Set [Name "c"] (NumLit "5")] Nothing) +> ,(TestStatement SQL2011 "update t set a=b where a>5" +> $ Update [Name "t"] Nothing +> [Set [Name "a"] (Iden [Name "b"])] +> $ Just $ BinOp (Iden [Name "a"]) [Name ">"] (NumLit "5")) - Data manipulation 971 - IWD 9075-2:201?(E) -14.14 +> ,(TestStatement SQL2011 "update t as u set a=b where u.a>5" +> $ Update [Name "t"] (Just $ Name "u") +> [Set [Name "a"] (Iden [Name "b"])] +> $ Just $ BinOp (Iden [Name "u",Name "a"]) +> [Name ">"] (NumLit "5")) - ii) Neither BSTARTCOL nor BENDCOL shall be an explicit contained in the - . - iii) Let FROMVAL be . FROMVAL shall not generally contain a reference to a - column of T or a whose subject routine is an SQL-invoked routine that - is possibly non-deterministic or that possibly modifies SQL-data. - iv) Let TOVAL be . TOVAL shall not generally contain a reference to a column - of T or a whose subject routine is an SQL-invoked routine that is possibly - non-deterministic or that possibly modifies SQL-data. - v) Let SC be +> ,(TestStatement SQL2011 "update t set (a,b)=(3,5)" +> $ Update [Name "t"] Nothing +> [SetMultiple [[Name "a"],[Name "b"]] +> [NumLit "3", NumLit "5"]] Nothing) - TSC AND - (FROMVAL < TOVAL) AND - (BENDCOL > FROMVAL) AND - (BSTARTCOL < TOVAL) - - vi) The following two s are implicitly added to SCL: - - BSTARTCOL = CASE - WHEN BSTARTCOL > FROMVAL - THEN BSTARTCOL - ELSE CAST ( FROMVAL AS BCD ) - END, - BENDCOL = CASE - WHEN BENDCOL < TOVAL - THEN BENDCOL - ELSE CAST ( TOVAL AS BCD ) - END - - b) Otherwise, let SC be TSC. -8) If UPS is contained in a , then SC shall not contain a that - specifies a parameter reference. -9) Case: - a) If is specified, then let CN be that . CN is an exposed . - b) Otherwise, let CN be the
contained in TT. CN is an exposed
. -10) The scope of CN is SCL and SC. - - -Access Rules -1) Case: - a) If USS is contained, without an intervening that specifies SQL SECURITY - INVOKER, in an , then let A be the that owns - that schema. - i) The applicable privileges for A for T shall include UPDATE for each . - - - - -972 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.14 - - ii) If TT immediately contains ONLY, then the applicable privileges for A shall include SELECT - WITH HIERARCHY OPTION on at least one supertable of T. - b) Otherwise, - i) The current privileges for T shall include UPDATE for each . - ii) If TT immediately contains ONLY, then the current privileges shall include SELECT WITH - HIERARCHY OPTION on at least one supertable of T. - - -General Rules -1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch - of the current SQL-transaction at the current SQL-connection is read-only and T is not a temporary table, - then an exception condition is raised: invalid transaction state — read-only SQL-transaction. -2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement - is being executed, then - Case: - a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the - successful execution of this statement shall be made visible to CR or an exception condition is raised: - cursor sensitivity exception — request failed. - b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made - visible to CR is implementation-defined. -3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution - of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception - — request failed. -4) The extent to which an SQL-implementation may disallow independent changes that are not significant is - implementation-defined. -5) Case: - a) If TT contains ONLY, then SC is effectively evaluated for each row of T with the exposed s or
s bound to that row, and the subject rows are those rows for which - the result of SC is True and for which there is no subrow in a proper subtable of T. SC is effectively - evaluated for each row of T before updating any row of T. - b) Otherwise, SC is effectively evaluated for each row of T with the exposed s or -
s of TT bound to that row, and the subject rows are those rows for which the - result of SC is True. SC is effectively evaluated for each row of T before updating any row of T. -6) Let S be the set consisting of every subject row. S is the old delta table of update operation on T. If FOR - PORTION OF is specified, then FROMVAL and TOVAL are associated with every row in S as the associated - for portion of from-value and the associated for portion of to-value, respectively. -7) If T is a base table, then each subject row is also an object row; otherwise, an object row is any row of a - leaf generally underlying table of T from which a subject row is derived. -8) If any row in the set of object rows has been marked for deletion by any , - , or that iden- - - - - Data manipulation 973 - IWD 9075-2:201?(E) -14.14 - - tifies some open cursor CR or updated by any , , or that identifies some open cursor CR, - then a completion condition is raised: warning — cursor operation conflict. -9) SC is evaluated for each row of T prior to the invocation of any caused by the update - of any row of T. -10) The of each contained in SCL is effectively evaluated for each row of T - before any row of T is updated. -11) For each subject row, a candidate new row is constructed by copying the subject row and updating it as - specified by each contained in SCL by applying the General Rules of Subclause 14.15, “”. - NOTE 484 — The data values allowable in the object rows may be constrained by a WITH CHECK OPTION constraint. - The effect of a WITH CHECK OPTION constraint is defined in the General Rules of Subclause 15.15, “Effect of replacing - some rows in a viewed table”. - -12) Let CL be the columns of T identified by the s contained in SCL. -13) Each subject row SR is identified for replacement, by its corresponding candidate new row CNR, in T. The - set of (SR, CNR) pairs is the replacement set for T. - NOTE 485 — Identifying a row for replacement, associating a replacement row with an identified row, and associating a - replacement set with a table are implementation-dependent operations. - -14) Case: - a) If T is a base table, then: - i) Case: - 1) If TT specifies ONLY, then T is identified for replacement processing without subtables - with respect to object columns CL. - 2) Otherwise, T is identified for replacement processing with subtables with respect to object - columns CL. - NOTE 486 — Identifying a base table for replacement processing, with or without subtables, is an implemen- - tation-dependent mechanism. In general, though not here, the list of object columns can be empty. - - ii) The General Rules of Subclause 15.13, “Effect of replacing rows in base tables”, are applied. - b) If T is a viewed table, then the General Rules of Subclause 15.15, “Effect of replacing some rows in - a viewed table”, are applied with TT as VIEW NAME and the replacement set for T as REPLACEMENT - SET FOR VIEW NAME. -15) If the set of object rows is empty, then a completion condition is raised: no data. - - -Conformance Rules -1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain an - in which either of the following is true: - a) A leaf generally underlying table of T is an underlying table of any broadly con- - tained in the . - - - - -974 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.14 - - b) The broadly contains a , , , or whose subject routine is an external routine that possibly reads - SQL-data. -2) Without Feature T111, “Updatable joins, unions, and columns”, conforming SQL language shall not contain - an that contains a that identifies a table that is not simply - updatable. -3) Without Feature T181, “Application-time period tables”, in conforming SQL language, an shall not contain FOR PORTION OF. - - - - - Data manipulation 975 - IWD 9075-2:201?(E) -14.15 14.15 -Function -Specify a list of updates. - - -Format ::= [ { }... ] @@ -2127,295 +345,14 @@ Format | - -Syntax Rules -1) Let T be the table identified by the contained in the containing , - , or . -2) If T is not trigger updatable, then each specified as an shall identify an - updatable column of T. - - - -976 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.15 - - NOTE 487 — The notion of updatable columns of base tables is defined in Subclause 4.15, “Tables”. The notion of updatable - columns of viewed tables is defined in Subclause 11.32, “”. - -3) No shall reference a column of which some underlying column is a system-time period - start column or a system-time period end column. -4) Each SC that immediately contains a is effectively replaced - by a MSCL as follows: - a) Let STN be the number of s contained in . - b) STN shall be equal to the degree of the AR contained in SC. - c) Let STi, 1 (one) ≤ i ≤ STN, be the i-th contained in the of SC and let DTi - be the declared type of the i-th field of AR. The i-th in MSCL is: - - STi = - CAST ( AR AS ROW ( F1 DT1, - F2 DT2, ..., - FSTN DTSTN ) ).Fi - - NOTE 488 — “Fn” here stands for the consisting of the letter “F” followed, with no intervening - by the decimal or s comprising a corresponding to the value n. - -5) If SC specifies an that references a column of which some underlying column - is either a generated column or an identity column whose descriptor indicates that values are always gen- - erated, then the specified in SC shall consist of a . -6) A simply contained in an in a shall not directly contain - a . -7) If the OSCL contains one or more s that contain a , then: - a) Let N be the number of s in OSCL that contain a . - b) For 1 (one) ≤ i ≤ N: - i) Let SCi be the i-th that contains a . - - ii) Let RCVEi be the immediately contained in SCi. - - iii) Let MSCi be the immediately contained in the immediately - contained in SCi. - - iv) Let OCi be the contained in MSCi. The declared type of the column identified - by OCi shall be a structured type. - - v) Let Mi be the number of s contained in MSCi. - - vi) For 1 (one) ≤ j ≤ Mi: - - Case: - 1) If j = 1 (one), then - A) Let MTi,1 be the immediately contained in MSCi. - - - - Data manipulation 977 - IWD 9075-2:201?(E) -14.15 - - B) Let MNi,1 be the immediately contained in MSCi. - - C) Let Vi,1 be: - - MTi,1 . MNi,1 ( RCVEi ) - - 2) Otherwise: - A) Let MTi,j be the immediately contained in the - immediately contained in MTi,j-1. - - B) Let MNi,j be the immediately contained in the - immediately contained in MTi,j-1. - - C) Let Vi,j be - - MTi,j . MNi,j ( Vi,j-1 ) - - c) OSCL is equivalent to a NSCL derived as follows: - i) Let NSCL be a derived from OSCL by replacing every SCa, 1 - (one) ≤ a ≤ N, that contains a with: - - MTa,Ma = Va,Ma - - ii) For 1 (one) ≤ b ≤ N, if there exists a c such that c < b and OCc is equivalent to OCb, then: - - 1) Every occurrence of OCb in Vb,Mb is replaced by Vc,Mc. - - 2) SCc is deleted from NSCL. - -8) Equivalent s shall not appear more than once in a . - NOTE 489 — Multiple occurrences of equivalent s within s are eliminated by the - preceding Syntax Rule of this Subclause. - -9) If the of SC specifies a CVS, then - the data type of CVS is the data type DT of the or specified in SC. -10) If CVS is an , then DT shall be a collection type or a distinct type whose source type - is a collection type. If CVS specifies ARRAY, then DT shall be an array type or a distinct type whose - source type is an array type. If CVS specifies MULTISET, then DT shall be a multiset type or a distinct - type whose source type is a multiset type. -11) For every in a , - Case: - a) If the immediately contains , then the declared type of - the column of T identified by the shall be an array type or a distinct type whose - source type is an array type. The Syntax Rules of Subclause 9.2, “Store assignment”, are applied with - a temporary site whose declared type is element type of the column of T identified by the as TARGET and the of the as VALUE. - - - - -978 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.15 - - b) Otherwise, the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with the column of T - identified by the as TARGET and the of the as VALUE. - - -Access Rules - None. - - -General Rules -1) A specifies one or more object columns and an update value. An object column is a column - identified by an in the . The update value is the value specified by the contained in the . -2) The value of the i-th object column denoted by C, is replaced as follows. - Case: - a) If the i-th contains an that immediately contains a , then - Case: - i) If the value of C is the null value, then an exception condition is raised: data exception — null - value in array target. - ii) Otherwise: - 1) Let N be the maximum cardinality of C. - 2) Let M be the cardinality of the value of C. - 3) Let I be the value of the immediately contained in . - 4) Let EDT be the element type of C. - 5) Case: - A) If I is greater than zero and less than or equal to M, then the value of C is replaced by - an array A with element type EDT and cardinality M derived as follows: - I) For j varying from 1 (one) to I–1 and from I+1 to M, the j-th element in A is - the value of the j-th element in C. - II) The General Rules of Subclause 9.2, “Store assignment”, are applied with I-th - element of A as TARGET and the i-th update value, denoted by SV as VALUE. - B) If I is greater than M and less than or equal to N, then the value of C is replaced by an - array A with element type EDT and cardinality I derived as follows: - I) For j varying from 1 (one) to M, the j-th element in A is the value of the j-th - element in C. - II) For j varying from M+1 to I–1, the j-th element in A is the null value. - - - - - Data manipulation 979 - IWD 9075-2:201?(E) -14.15 - - III) The General Rules of Subclause 9.2, “Store assignment”, are applied with I-th - element of A as TARGET and the i-th update value, denoted by SV as VALUE. - C) Otherwise, an exception condition is raised: data exception — array element error. - b) Otherwise, the value of C is replaced by the i-th update value, denoted by SV. The General Rules of - Subclause 9.2, “Store assignment”, are applied with C as TARGET and SV as VALUE. - - -Conformance Rules -1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain a in which either of the following is true: - a) A leaf generally underlying table of T is an underlying table of any broadly con- - tained in any simply contained in an or immedi- - ately contained in the . - b) An or immediately contained in the broadly contains - a , , , or - whose subject routine is an external routine that possibly reads SQL-data. -2) Without Feature S091, “Basic array support”, conforming SQL language shall not contain an that immediately contains a . -3) Without Feature S024, “Enhanced structured types”, conforming SQL language shall not contain a in which the declared type of the in the is a structured type TY and - the declared type of the or corresponding field of the contained in the - is not TY. -4) Without Feature S024, “Enhanced structured types”, conforming SQL language shall not contain a that contains a and in which the declared type of the last - identifies a structured type TY, and the declared type of the contained in the - is not TY. -5) Without Feature T641, “Multiple column assignment”, conforming SQL language shall not contain a - . - - - - -980 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.16 - - 14.16 -This Subclause is modified by Subclause 12.8, “”, in ISO/IEC 9075-4. - - -Function -Declare a declared local temporary table. - - -Format ::= DECLARE LOCAL TEMPORARY TABLE
[ ON COMMIT
ROWS ] - -Syntax Rules -1) Let TN be the
of a TTD, and let T be the - of TN. -2)  04  TTD shall be contained in an . -3) Case: - a) If TN contains a LSQ, then LSQ shall be “MODULE”. - b) If TN does not contain a , then “MODULE” is implicit. -4)  04  If a is contained in an M, then the - - of TN shall not be equivalent to the of the
of - any other that is contained in M. -5) The descriptor of the table defined by a includes TN and the column - descriptor specified by each . The i-th column descriptor is given by the i-th . -6)
shall contain at least one or at least one . -7)
shall not contain a
that is a
. -8) If ON COMMIT is not specified, then ON COMMIT DELETE ROWS is implicit. - - -Access Rules - None. - - -General Rules -1) Let U be the implementation-dependent of the schema that contains the declared local - temporary table such that U does not contain a table whose
is equivalent to TN. -2) Let UI be the current user identifier and let R be the current role name. - - - Data manipulation 981 - IWD 9075-2:201?(E) -14.16 - - Case: - a) If UI is not the null value, then let A be UI. - b) Otherwise, let A be R. -3)  04  The definition of T within an SQL-client module is effectively equivalent to the definition of a persistent - - base table U.T. Within the SQL-client module, any reference to MODULE.T is equivalent to a reference - to U.T. -4) A set of privilege descriptors is created that define the privileges INSERT, SELECT, UPDATE, DELETE, - and REFERENCES on this table and INSERT, SELECT, UPDATE, and REFERENCES for every in the table definition to A. These privileges are not grantable. The grantor for each of these - privilege descriptors is set to the special grantor value “_SYSTEM”. The grantee is “PUBLIC”. -5) The definition of a temporary table persists for the duration of the SQL-session. The termination of the - SQL-session is effectively followed by the execution of the following with the - current authorization identifier A and current U without further Access Rule checking: - - DROP TABLE T CASCADE - -6) The definition of a declared local temporary table does not appear in any view of the Information Schema. - NOTE 490 — The Information Schema is defined in [ISO9075-11]. - - -Conformance Rules -1) Without Feature F531, “Temporary tables”, conforming SQL language shall not contain a . - - - - -982 Foundation (SQL/Foundation) - IWD 9075-2:201?(E) - 14.17 - - 14.17 -Function -Remove the association between a locator variable and the value that is represented by that locator. - - -Format ::= FREE LOCATOR [ { }... ] @@ -2424,74 +361,10 @@ Format | | - -Syntax Rules -1) Each host parameter identified by immediately contained in - shall be a binary large object locator parameter, a character large object locator parameter, an array locator - parameter, a multiset locator parameter, or a user-defined type locator parameter. -2) Each host variable identified by the immediately contained in shall be a binary large object locator variable, a character large object locator variable, an array - locator variable, a multiset locator variable, or a user-defined type locator variable. - - -Access Rules - None. - - -General Rules -1) For every LR immediately contained in , let L be the value of - LR. - Case: - a) If L is not a valid locator value, then an exception condition is raised: locator exception — invalid - specification. - b) Otherwise, L is marked invalid. - - -Conformance Rules -1) Without Feature T561, “Holdable locators”, conforming SQL language shall not contain a . - - - - - Data manipulation 983 - IWD 9075-2:201?(E) 14.18 - -14.18 - -Function -Mark a locator variable as being holdable. - - -Format ::= HOLD LOCATOR [ { }... ] -Syntax Rules -1) Each host parameter identified by immediately contained in - shall be a binary large object locator parameter, a character large object locator parameter, an array locator - parameter, a multiset locator parameter, or a user-defined type locator parameter. - - -Access Rules - None. - - -General Rules -1) For every LR immediately contained in , let L be the value - of LR. - Case: - a) If L is not a valid locator value, then an exception condition is raised: locator exception — invalid - specification. - b) Otherwise, L is marked holdable. - - -Conformance Rules -1) Without Feature T561, “Holdable locators”, conforming SQL language shall not contain a . - - - +> ] diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs index 9955dd4..85d85cc 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Queries.lhs @@ -2476,6 +2476,9 @@ Specify a function yielding a value of a multiset type. ::= SET +TODO: set is now a reserved keyword. Fix the set parsing with a +special case term. + > multisetValueFunction :: TestItem > multisetValueFunction = Group "multiset value function" > $ map (uncurry (TestValueExpr SQL2011)) diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs index fee82c0..aa8e972 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs @@ -6,9 +6,11 @@ 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" [] +> sql2011SchemaTests = Group "sql 2011 schema tests" +> [ 11.1 @@ -18,6 +20,12 @@ This module covers the tests for parsing schema and DDL statements. [ ] [ ... ] +> (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 + ::= | @@ -66,6 +74,14 @@ This module covers the tests for parsing schema and DDL statements. 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
@@ -74,6 +90,9 @@ This module covers the tests for parsing schema and DDL statements. [ WITH ] [ ON COMMIT
ROWS ] + ,(TestStatement SQL2011 "create table ( a int )" + +
::=
| @@ -1310,3 +1329,5 @@ This module covers the tests for parsing schema and DDL statements. ::= DROP SEQUENCE + +> ] diff --git a/tools/Language/SQL/SimpleSQL/TestTypes.lhs b/tools/Language/SQL/SimpleSQL/TestTypes.lhs index c34f4a2..09de915 100644 --- a/tools/Language/SQL/SimpleSQL/TestTypes.lhs +++ b/tools/Language/SQL/SimpleSQL/TestTypes.lhs @@ -17,7 +17,8 @@ to lots of tricky exceptions/variationsx. > data TestItem = Group String [TestItem] > | TestValueExpr Dialect String ValueExpr > | TestQueryExpr Dialect String QueryExpr -> | TestQueryExprs Dialect String [QueryExpr] +> | TestStatement Dialect String Statement +> | TestStatements Dialect String [Statement] this just checks the sql parses without error, mostly just a intermediate when I'm too lazy to write out the parsed AST. These diff --git a/tools/Language/SQL/SimpleSQL/Tests.lhs b/tools/Language/SQL/SimpleSQL/Tests.lhs index 1dfe6f9..bf45c23 100644 --- a/tools/Language/SQL/SimpleSQL/Tests.lhs +++ b/tools/Language/SQL/SimpleSQL/Tests.lhs @@ -73,8 +73,10 @@ order on the generated documentation. > toTest parseValueExpr prettyValueExpr d str expected > itemToTest (TestQueryExpr d str expected) = > toTest parseQueryExpr prettyQueryExpr d str expected -> itemToTest (TestQueryExprs d str expected) = -> toTest parseQueryExprs prettyQueryExprs d str expected +> itemToTest (TestStatement d str expected) = +> toTest parseStatement prettyStatement d str expected +> itemToTest (TestStatements d str expected) = +> toTest parseStatements prettyStatements d str expected > itemToTest (ParseQueryExpr d str) = > toPTest parseQueryExpr prettyQueryExpr d str diff --git a/tools/SimpleSqlParserTool.lhs b/tools/SimpleSqlParserTool.lhs index 4191254..be14bcc 100644 --- a/tools/SimpleSqlParserTool.lhs +++ b/tools/SimpleSqlParserTool.lhs @@ -67,7 +67,7 @@ indent: parse then pretty print sql > (f,src) <- getInput args > either (error . peFormattedError) > (putStrLn . ppShow) -> $ parseQueryExprs SQL2011 f Nothing src +> $ parseStatements SQL2011 f Nothing src > ) > lexCommand :: (String,[String] -> IO ()) @@ -87,7 +87,7 @@ indent: parse then pretty print sql > ,\args -> do > (f,src) <- getInput args > either (error . peFormattedError) -> (putStrLn . prettyQueryExprs SQL2011) -> $ parseQueryExprs SQL2011 f Nothing src +> (putStrLn . prettyStatements SQL2011) +> $ parseStatements SQL2011 f Nothing src > )