BNF for sqlgrammar.jj

NON-TERMINALS

/*
 * Statement
 */
Statement
Statement ::= StatementPart <EOF>

/**
 * Parse a search condition.
 *
 * @param sqlFragment a fragment of an SQL statement, representing a
 *                    search condition
 * @return a {@code ValueNode} representing the search condition
 */
SearchCondition
SearchCondition ::= valueExpression <EOF>



proceduralStatement
proceduralStatement ::= ( insertStatement | preparableUpdateStatement | preparableDeleteStatement | preparableSelectStatement | mergeStatement | callStatement )

/*
 * StatementPart
 * 
 * @param tokenHolder returns the token that starts
 * the statement.  If null, ignored.
 */
StatementPart
StatementPart ::= ( spsRenameStatement | lockStatement )
| ( createStatements | dropStatements | spsAlterStatement | globalTemporaryTableDeclaration | preparableSQLDataStatement | spsSetStatement | truncateTableStatement | grantStatement | revokeStatement | execStatement )

/*
 * spsCreateStatement
 */
createStatements
createStatements ::= <CREATE> ( ( schemaDefinition | viewDefinition | triggerDefinition | synonymDefinition | roleDefinition | sequenceDefinition ) | tableDefinition | procedureDefinition | functionDefinition | aggregateDefinition | udtDefinition | indexDefinition )

/*
 * spsDropStatement
 */
dropStatements
dropStatements ::= <DROP> ( dropSchemaStatement | dropTableStatement | dropIndexStatement | dropAliasStatement | dropViewStatement | dropTriggerStatement | dropRoleStatement | dropSequenceStatement )

/*
 * spsAlterStatement
 */
spsAlterStatement
spsAlterStatement ::= <ALTER> ( alterTableStatement )

/*
 * spsSetStatement
 */
spsSetStatement
spsSetStatement ::= <SET> ( setIsolationStatement | setSchemaStatement | setMessageLocaleStatement | setRoleStatement | setConstraintsStatement )
| <SET> ( setSchemaStatement | setIsolationStatement )

/**
 * constraintsReference
 */
constraintsReference
constraintsReference ::= qualifiedName

/**
 * setConstraintsStatement
 */
setConstraintsStatement
setConstraintsStatement ::= <CONSTRAINTS> ( constraintsReference ( <COMMA> constraintsReference )* | <ALL> ) ( <DEFERRED> | <IMMEDIATE> )

/*
 * preparableSQLDataStatement
 *
 * preparableSQLDataStatement differs from
 * directSQLDataStatement in that it
 * supports positioned update and delete
 * and a preparable select (with FOR UPDATE)
 * instead of a direct select (without FOR UPDATE)
 */
preparableSQLDataStatement
preparableSQLDataStatement ::= preparableDeleteStatement
| preparableSelectStatement
| insertStatement
| mergeStatement
| preparableUpdateStatement
| callStatement
| savepointStatement

/*
 * preparableDeleteStatement
 *
 *	This may be a search or positioned delete statement.
 */
preparableDeleteStatement
preparableDeleteStatement ::= <DELETE> deleteBody



deleteBody
deleteBody ::= <FROM> newInvocation ( <WHERE> whereClause )?
| <FROM> qualifiedName ( ( <AS> )? identifier )? ( propertyList <CHECK_PROPERTIES> )? ( <WHERE> ( currentOfClause | whereClause ) )?

/*
 * currentOfClause
 */
currentOfClause
currentOfClause ::= <CURRENT> <OF> identifier

/*
 * preparableSelectStatement
 *
 *
 *	The preparable select statement is a superset of
 *	the directSelectStatementMultipleRows in that it
 *	allows both the preparable single row select statement
 *	(a query expression that returns one row, although it
 *	is also handled like a cursor) and the preparable
 *	multiple row select statement, which allows not only
 *	an order by clause but also a for update clause.
 */
preparableSelectStatement
preparableSelectStatement ::= queryExpression ( orderByClause )? offsetFetchFirstClause ( <FOR> forUpdateClause )? ( atIsolationLevel )?

/*
 * insertStatement
 */
insertStatement
insertStatement ::= <INSERT> <INTO> targetTable insertColumnsAndSource



targetTable
targetTable ::= newInvocation
| qualifiedName

/*
 * preparableUpdateStatement
 */
preparableUpdateStatement
preparableUpdateStatement ::= <UPDATE> updateBody



tableOrIndex
tableOrIndex ::= <TABLE>
| <INDEX>



updateBody
updateBody ::= newInvocation <SET> setClauseList ( <WHERE> whereClause )?
| qualifiedName ( ( <AS> )? identifier )? ( propertyList <CHECK_PROPERTIES> )? <SET> setClauseList ( <WHERE> ( whereClause | currentOfClause ) )?

/*
 * callStatement
 */
callStatement
callStatement ::= ( bareCallStatement | <LEFT_BRACE> bareCallStatement <RIGHT_BRACE> )

/*
 * baseCallStatement
 */
bareCallStatement
bareCallStatement ::= <CALL> primaryExpression
| dynamicParameterSpecification <EQUALS_OPERATOR> <CALL> rowValueConstructor

/*
 * mergeStatement
 */
mergeStatement
mergeStatement ::= <MERGE> <INTO> tableFactor <USING> tableFactor joinCondition matchingClauseList

/*
 * matchingClauseList
 */
matchingClauseList
matchingClauseList ::= matchingClause ( matchingClause )*

/*
 * matchingClause
 */
matchingClause
matchingClause ::= <WHEN> <MATCHED> ( <AND> valueExpression )? <THEN> ( <DELETE> | <UPDATE> <SET> setClauseList )
| <WHEN> <NOT> <MATCHED> ( <AND> valueExpression )? <THEN> <INSERT> ( <LEFT_PAREN> insertColumnList <RIGHT_PAREN> )? <VALUES> <LEFT_PAREN> rowValueConstructorList <RIGHT_PAREN>

/*
 * primaryExpression
 */
primaryExpression
primaryExpression ::= routineInvocation
| primaryExpressionXX

/* 
 * savepointStatement

	savepointStatementClauses contains the UNIQUE, ON ROLLBACK RETAIN LOCKS, ON ROLLBACK RETAIN CURSORS clauses.

	0 - Boolean - UNIQUE clause
	1 - Boolean - ON ROLLBACK RETAIN LOCKS clause
	2 - Boolean - ON ROLLBACK RETAIN CURSORS clause
 */
savepointStatement
savepointStatement ::= ( <SAVEPOINT> identifier ( savepointStatementClause )+ | <ROLLBACK> ( <WORK> )? <TO> <SAVEPOINT> ( identifier )? | <RELEASE> ( <TO> )? <SAVEPOINT> identifier )



savepointStatementClause
savepointStatementClause ::= ( <UNIQUE> | <ON> <ROLLBACK> <RETAIN> ( LocksOrCursors ) )

/*
 * LocksOrCursors
 */
LocksOrCursors
LocksOrCursors ::= <LOCKS>
| <CURSORS>

/* 
 * globalTemporaryTableDeclaration

	declareTableClauses contains the NOT LOGGED, on commit and on rollback clauses.

	0 - Boolean - NOT LOGGED clause
	1 - Boolean - on commit behavior
	2 - Boolean - on rollback behavior
 */
globalTemporaryTableDeclaration
globalTemporaryTableDeclaration ::= <DECLARE> <GLOBAL> <TEMPORARY> <TABLE> qualifiedName tableElementList ( declareTableClause )+



declareTableClause
declareTableClause ::= ( <NOT> <LOGGED> | <ON> <COMMIT> ( onCommit ) <ROWS> | <ON> <ROLLBACK> <DELETE> <ROWS> )

/*
 * onCommit
 */
onCommit
onCommit ::= <PRESERVE>
| <DELETE>

/*
 * tableElementList
 */
tableElementList
tableElementList ::= <LEFT_PAREN> tableElement ( <COMMA> tableElement )* <RIGHT_PAREN>

/*
 * tableElement
 */
tableElement
tableElement ::= columnDefinition
| tableConstraintDefinition

/*
 * columnDefinition
 */
columnDefinition
columnDefinition ::= identifier ( ( dataTypeDDL ) )? ( defaultAndConstraints )?

/*
 * defaultAndConstraints
 */
defaultAndConstraints
defaultAndConstraints ::= columnConstraintDefinition ( columnConstraintDefinition )* ( defaultClause ( columnConstraintDefinition )* )?
| defaultClause ( columnConstraintDefinition )*

/*
 * dataTypeDDL
 */
dataTypeDDL
dataTypeDDL ::= dataTypeCommon
| javaType

/**
   Returns  a dataTypeDDL() as a catalog type, ie.
   the Java interface TypeDescriptor.
*/
catalogType
catalogType ::= dataTypeDDL

/*
 * dataTypeCast
 */
dataTypeCast
dataTypeCast ::= dataTypeCommon
| javaType

/*
 * dataTypeCommon
 */
dataTypeCommon
dataTypeCommon ::= ( ( characterStringType ) | ( nationalCharacterStringType ) | numericType | datetimeType | <BOOLEAN> | longType | LOBType | XMLType )

/*
 * characterStringType
 */
characterStringType
characterStringType ::= ( ( <VARCHAR> charLength ) | charOrCharacter ( <VARYING> charLength | ( charLength )? ) ) ( forBitData )?

/*
 * charOrCharacter
 */
charOrCharacter
charOrCharacter ::= <CHAR>
| <CHARACTER>

/*
 * charType
 */
charLength
charLength ::= <LEFT_PAREN> length <RIGHT_PAREN>

/*
** forBitData
*/
forBitData
forBitData ::= <FOR> <BIT> <DATA>

/*
 * nationalCharacterStringType
 */
nationalCharacterStringType
nationalCharacterStringType ::= ( <NATIONAL> charOrCharacter ( <VARYING> charLength | ( charLength )? ) | <NCHAR> ( <VARYING> charLength | ( charLength )? ) | <NVARCHAR> ( charLength ) )

/*
 * lobType
 */
LOBType
LOBType ::= ( <BLOB> ( lengthAndModifier )? | <CLOB> ( lengthAndModifier )? | <NCLOB> lengthAndModifier | <BINARY> <LARGE> <OBJECT> ( lengthAndModifier )? | charOrCharacter <LARGE> <OBJECT> ( lengthAndModifier )? | <NATIONAL> <CHARACTER> <LARGE> <OBJECT> lengthAndModifier )

/*
 * numericType
 */
numericType
numericType ::= exactNumericType
| approximateNumericType

/*
 * exactNumericType
 */
exactNumericType
exactNumericType ::= ( <NUMERIC> | <DECIMAL> | <DEC> ) ( <LEFT_PAREN> precision ( <COMMA> scale )? <RIGHT_PAREN> )?
| exactIntegerType

/*
 * exactNumericType
 */
exactIntegerType
exactIntegerType ::= ( <INTEGER> | <INT> )
| <SMALLINT>
| <BIGINT>

/*
 * approximateNumericType
 */
approximateNumericType
approximateNumericType ::= <FLOAT> ( <LEFT_PAREN> precision <RIGHT_PAREN> )?
| <REAL>
| doubleType

/*
 * doubleType
 */
doubleType
doubleType ::= ( <DOUBLE> <PRECISION> | <DOUBLE> )

/*
 * longType
 */
longType
longType ::= <LONG> longSubType



longSubType
longSubType ::= <VARCHAR> ( forBitData )?
| <NVARCHAR>

/*
 * XMLType
 */
XMLType
XMLType ::= <XML>

/*
 * xmlDocOrContent
 *
 * Parse the XML keywords DOCUMENT and CONTENT.  We don't
 * support CONTENT yet, so we throw an appropriate error
 * if we see it.
 *
 */
xmlDocOrContent
xmlDocOrContent ::=
| <CONTENT>
| <DOCUMENT>

/*
 * javaType
 */
javaType
javaType ::= qualifiedName

/*
 * javaDSL
 *
 * A Java dot-separated list.
 */
javaDSL
javaDSL ::= caseSensitiveIdentifierPlusReservedWords ( javaDSLNameExtender )*

/*
 * javaClassName
 */
javaClassName
javaClassName ::= javaDSL

/*
 * javaDSLNameExtender
 */
javaDSLNameExtender
javaDSLNameExtender ::= <PERIOD> caseSensitiveIdentifierPlusReservedWords

/*
 * lengthAndModifier
 */
lengthAndModifier
lengthAndModifier ::= <LEFT_PAREN> ( <LENGTH_MODIFIER> | <EXACT_NUMERIC> ( <IDENTIFIER> )? ) <RIGHT_PAREN>

/*
 * length
 */
length
length ::= <EXACT_NUMERIC>

/*
 * exactNumber
*/
exactNumber
exactNumber ::= ( sign )? <EXACT_NUMERIC>

/*
 * precision
 */
precision
precision ::= uint_value

/*
 * uint_value
 */
uint_value
uint_value ::= <EXACT_NUMERIC>

/*
 * scale
 */
scale
scale ::= uint_value

/*
 * datetimeType
 */
datetimeType
datetimeType ::= <DATE>
| <TIME>
| <TIMESTAMP>

/*
 * qualifiedName
 */
qualifiedName
qualifiedName ::= identifier ( <PERIOD> identifier )?

/*
 * queryExpression
 *
 * We have to be carefull to get the associativity correct. According to the SQL spec
 *    ::=
 *     
 *    |  UNION [ ALL ] 
 *    |  EXCEPT [ ALL ] 
 * Meaning that
 *   t1 UNION ALL t2 UNION t3
 * is equivalent to
 *   (t1 UNION ALL t2) UNION t3
 * However recursive descent parsers want recursion to be on the right, so this kind of associativity is unnatural
 * for our parser. The queryExpression method must know whether it is being called as the right hand side of a
 * set operator to produce a query tree with the correct associativity.
 */
queryExpression
queryExpression ::= nonJoinQueryTerm ( unionOrExcept )?

/*
 * unionOrExcept
 */
unionOrExcept
unionOrExcept ::= <UNION> ( <ALL> | <DISTINCT> )? queryExpression
| <EXCEPT> ( <ALL> | <DISTINCT> )? queryExpression

/*
 * nonJoinQueryTerm
 *
 * Be careful with the associativity of INTERSECT. According to the SQL spec
 *   t1 INTERSECT t2 INTERSECT ALL t3
 * is equivalent to
 *   (t1 INTERSECT t2) INTERSECT ALL t3
 * which is not the same as
 *   t1 INTERSECT (t2 INTERSECT ALL t3)
 * See the comment on queryExpression.
 */
nonJoinQueryTerm
nonJoinQueryTerm ::= nonJoinQueryPrimary ( intersect )?

/*
 * intersect
 */
intersect
intersect ::= <INTERSECT> ( <ALL> | <DISTINCT> )? nonJoinQueryTerm

/*
 * nonJoinQueryPrimary
 */
nonJoinQueryPrimary
nonJoinQueryPrimary ::= simpleTable
| <LEFT_PAREN> queryExpression ( orderByClause )? offsetFetchFirstClause <RIGHT_PAREN>

/*
 * simpleTable
 */
simpleTable
simpleTable ::= querySpecification
| tableValueConstructor

/*
 * querySpecification
 */
querySpecification
querySpecification ::= <SELECT> ( setQuantifier )? selectList tableExpression

/*
 * setQuantifier
 */
setQuantifier
setQuantifier ::= <DISTINCT>
| <ALL>

/*
 * selectList
 */
selectList
selectList ::= <ASTERISK>
| selectColumnList



selectColumnList
selectColumnList ::= selectSublist ( <COMMA> selectSublist )*

/*
 * selectSublist
 */
selectSublist
selectSublist ::= qualifiedName <PERIOD> <ASTERISK>
| derivedColumn

/*
 * derivedColumn
 */
derivedColumn
derivedColumn ::= valueExpression ( asClause )?

/*
 * asClause
 */
asClause
asClause ::= ( <AS> )? identifier

/*
 * valueExpression
 */
valueExpression
valueExpression ::= orExpression ( <OR> orExpression )*

/*
 * orExpression
 */
orExpression
orExpression ::= andExpression ( <AND> andExpression )*

/*
 * andExpression
 */
andExpression
andExpression ::= ( <NOT> )? isSearchCondition

/*
 * isSearchCondition
 */
isSearchCondition
isSearchCondition ::= booleanPrimary

/*
 * booleanPrimary
 */
booleanPrimary
booleanPrimary ::= predicate

/*
 * predicate
 */
predicate
predicate ::= ( additiveExpression | existsExpression ) ( remainingPredicate )*

/*
 * remainingPredicates
 */
remainingPredicate
remainingPredicate ::= remainingNonNegatablePredicate
| ( <NOT> )? remainingNegatablePredicate

/*
 * remainingNonNegatablePredicate
 */
remainingNonNegatablePredicate
remainingNonNegatablePredicate ::= compOp ( ( quantifier <LEFT_PAREN> tableSubquery <RIGHT_PAREN> ) | ( additiveExpression ) )

/*
 * remainingNegatablePredicate
 */
remainingNegatablePredicate
remainingNegatablePredicate ::= <IN> inPredicateValue
| <IS> ( <NOT> )? <NULL>
| <LIKE> additiveExpression ( <ESCAPE> additiveExpression | <LEFT_BRACE> <ESCAPE> additiveExpression <RIGHT_BRACE> )?
| <BETWEEN> additiveExpression <AND> additiveExpression

/*
 * compOp
 */
compOp
compOp ::= <EQUALS_OPERATOR>
| <NOT_EQUALS_OPERATOR>
| <NOT_EQUALS_OPERATOR2>
| <LESS_THAN_OPERATOR>
| <GREATER_THAN_OPERATOR>
| <LESS_THAN_OR_EQUALS_OPERATOR>
| <GREATER_THAN_OR_EQUALS_OPERATOR>

/*
 * additiveExpression
 */
additiveExpression
additiveExpression ::= multiplicativeExpression ( additiveOperator multiplicativeExpression )*

/*
 * additiveOperator
 */
additiveOperator
additiveOperator ::= <PLUS_SIGN>
| <MINUS_SIGN>

/*
 * multiplicativeExpression
 */
multiplicativeExpression
multiplicativeExpression ::= unaryExpression ( multiplicativeOperator unaryExpression )*

/*
 * multiplicativeOperator
 */
multiplicativeOperator
multiplicativeOperator ::= <ASTERISK>
| <SOLIDUS>
| <CONCATENATION_OPERATOR>

/*
 * unaryExpression
 */
unaryExpression
unaryExpression ::= ( sign )? primaryExpression

/*
 * sign
 */
sign
sign ::= <PLUS_SIGN>
| <MINUS_SIGN>

/*
 * primaryExpressionXX
 */
primaryExpressionXX
primaryExpressionXX ::= primary ( nonStaticMethodCallOrFieldAccess )*



nonStaticMethodCallOrFieldAccess
nonStaticMethodCallOrFieldAccess ::= nonStaticMethodInvocation

/*
 * nonStaticMethodInvocation
 */
nonStaticMethodInvocation
nonStaticMethodInvocation ::= ( <FIELD_REFERENCE> | <PERIOD> ) methodName methodCallParameterList
| <PERIOD> methodName

/*
 * methodName
 */
methodName
methodName ::= caseSensitiveIdentifierPlusReservedWords

/*
 * staticMethodName
 */
staticMethodName
staticMethodName ::= caseSensitiveIdentifierPlusReservedWords

/*
 * methodParameter
 */
methodParameter
methodParameter ::= valueExpression
| nullSpecification

/*
 * primary
 */
primary
primary ::= staticClassReference
| valueExpressionPrimary

/*
 * staticClassReference
 */
staticClassReference
staticClassReference ::= javaClass <DOUBLE_COLON> staticClassReferenceType

/*
 * staticClassReferenceType
 */
staticClassReferenceType
staticClassReferenceType ::= staticMethodInvocation
| staticClassFieldReference

/*
 * staticClassFieldReference
 */
staticClassFieldReference
staticClassFieldReference ::= caseSensitiveIdentifierPlusReservedWords

/*
 * nonSecondDatetimeField
 */
nonSecondDatetimeField
nonSecondDatetimeField ::= <YEAR>
| <MONTH>
| <DAY>
| <HOUR>
| <MINUTE>



escapedValueFunction
escapedValueFunction ::= miscBuiltinsCore
| <SUBSTRING> <LEFT_PAREN> additiveExpression <COMMA> additiveExpression ( <COMMA> additiveExpression )? <RIGHT_PAREN>
| <CURDATE> <LEFT_PAREN> <RIGHT_PAREN>
| <CURTIME> <LEFT_PAREN> <RIGHT_PAREN>
| <CONCAT> <LEFT_PAREN> additiveExpression <COMMA> additiveExpression <RIGHT_PAREN>
| userNode <LEFT_PAREN> <RIGHT_PAREN>
| timestampArithmeticFuncion
| escapedSYSFUNFunction

/*
 * numericValueFunction
 */
escapedSYSFUNFunction
escapedSYSFUNFunction ::= <IDENTIFIER> methodCallParameterList

/*
 * timestampArithmeticFuncion
 */
timestampArithmeticFuncion
timestampArithmeticFuncion ::= <TIMESTAMPADD> <LEFT_PAREN> jdbcIntervalType <COMMA> additiveExpression <COMMA> additiveExpression <RIGHT_PAREN>
| <TIMESTAMPDIFF> <LEFT_PAREN> jdbcIntervalType <COMMA> additiveExpression <COMMA> additiveExpression <RIGHT_PAREN>

/*
 * jdbcIntervalType
 */
jdbcIntervalType
jdbcIntervalType ::= <SQL_TSI_FRAC_SECOND>
| <SQL_TSI_SECOND>
| <SQL_TSI_MINUTE>
| <SQL_TSI_HOUR>
| <SQL_TSI_DAY>
| <SQL_TSI_WEEK>
| <SQL_TSI_MONTH>
| <SQL_TSI_QUARTER>
| <SQL_TSI_YEAR>

/*
 * numericValueFunction
 */
numericValueFunction
numericValueFunction ::= <ABS> absFunction
| <ABSVAL> absFunction
| <SQRT> <LEFT_PAREN> additiveExpression <RIGHT_PAREN>
| <MOD> modFunction
| <IDENTITY_VAL_LOCAL> <LEFT_PAREN> <RIGHT_PAREN>

/*
 * coalesceFunction
 */
coalesceFunction
coalesceFunction ::= <LEFT_PAREN> coalesceExpression ( <COMMA> coalesceExpression )* <RIGHT_PAREN>

/*
 * coalesceExpression
 */
coalesceExpression
coalesceExpression ::= additiveExpression

/*
 * absFunction
 */
absFunction
absFunction ::= <LEFT_PAREN> additiveExpression <RIGHT_PAREN>

/*
 * modFunction
 */
modFunction
modFunction ::= <LEFT_PAREN> additiveExpression <COMMA> additiveExpression <RIGHT_PAREN>

/*
 * datetimeField
 */
datetimeField
datetimeField ::= nonSecondDatetimeField
| <SECOND>



characterValueFunction
characterValueFunction ::= <SUBSTR> <LEFT_PAREN> additiveExpression <COMMA> additiveExpression ( <COMMA> additiveExpression )? <RIGHT_PAREN>
| ( <UPPER> | <LOWER> ) <LEFT_PAREN> additiveExpression <RIGHT_PAREN>
| ( <UCASE> | <LCASE> ) <LEFT_PAREN> additiveExpression <RIGHT_PAREN>
| trimFunction
| <LOCATE> <LEFT_PAREN> additiveExpression <COMMA> additiveExpression ( <COMMA> additiveExpression )? <RIGHT_PAREN>



trimFunction
trimFunction ::= trimType <LEFT_PAREN> additiveExpression <RIGHT_PAREN>
| <TRIM> ansiTrim



ansiTrim
ansiTrim ::= <LEFT_PAREN> ansiTrimSpec ( <FROM> additiveExpression <RIGHT_PAREN> | additiveExpression <FROM> additiveExpression <RIGHT_PAREN> )
| <LEFT_PAREN> additiveExpression ( <FROM> additiveExpression <RIGHT_PAREN> | <RIGHT_PAREN> )



ansiTrimSpec
ansiTrimSpec ::= <TRAILING>
| <LEADING>
| <BOTH>



trimType
trimType ::= <RTRIM>
| <LTRIM>

/*
 * valueExpressionPrimary
 */
valueExpressionPrimary
valueExpressionPrimary ::= <LEFT_BRACE> <FN> escapedValueFunction <RIGHT_BRACE>
| <CURRENT> ( <SCHEMA> | <SQLID> )
| <CURRENT> <ISOLATION>
| valueSpecification
| newInvocation
| windowOrAggregateFunctionNode
| miscBuiltins
| columnReference
| <LEFT_PAREN> ( subquery | valueExpression ) <RIGHT_PAREN>
| castSpecification
| nextValueExpression

/*
 * miscBuiltins
 */
miscBuiltins
miscBuiltins ::= miscBuiltinsCore
| datetimeValueFunction
| routineInvocation



miscBuiltinsCore
miscBuiltinsCore ::= <GET_CURRENT_CONNECTION> <LEFT_PAREN> <RIGHT_PAREN>
| numericValueFunction
| characterValueFunction
| dataTypeScalarFunction
| <COALESCE> coalesceFunction
| <VALUE> coalesceFunction
| <LENGTH> <LEFT_PAREN> additiveExpression <RIGHT_PAREN>
| xmlFunction

/*
 * dataTypeScalarFunction
 */
dataTypeScalarFunction
dataTypeScalarFunction ::= dateTimeScalarFunction
| numericFunctionType <LEFT_PAREN> additiveExpression <RIGHT_PAREN>
| charOrVarchar <LEFT_PAREN> additiveExpression ( <COMMA> length )? <RIGHT_PAREN>

/*
 * xmlFunction
 *
 * This method parses the built-in functions used with
 * the XML datatype.
 *
 */
xmlFunction
xmlFunction ::= <XMLPARSE> <LEFT_PAREN> xmlDocOrContent xmlParseValue <RIGHT_PAREN>
| <XMLSERIALIZE> <LEFT_PAREN> xmlSerializeValue <RIGHT_PAREN>
| <XMLEXISTS> <LEFT_PAREN> xmlQueryValue <RIGHT_PAREN>
| <XMLQUERY> <LEFT_PAREN> xmlQueryValue <RIGHT_PAREN>

/*
 * xmlParseValue
 *
 * Syntax is as follows:
 *
 *     XMLPARSE( DOCUMENT  PRESERVE WHITESPACE )
 *
 * The result of this operation will be an XML value, which can either
 * be used transiently or else can be stored persistently in a table that
 * has an XML column.  For example:
 *
 * ij> CREATE TABLE x_table (id INT, xdoc XML);
 * 0 rows inserted/updated/deleted
 * ij> INSERT INTO x_table VALUES (1, XMLPARSE(DOCUMENT ' doc '
 * PRESERVE WHITESPACE));
 * 1 row inserted/updated/deleted
 *
 * We only allow XML documents (as opposed to XML content) to be
 * parsed into XML values.  Note that we require the "PRESERVE WHITESPACE"
 * keyword to be explicit; this is because the SQL/XML (2003) spec says that
 * if no whitespace option is given, the default is "STRIP WHITESPACE", which
 * we don't support (yet).
 *
 * By the time we get to this method, the "DOCUMENT" keyword has already
 * been parsed.
 *
 */
xmlParseValue
xmlParseValue ::= additiveExpression xmlPreserveWhitespace

/*
 * xmlPreserveWhitespace
 *
 * For now, we only support the PRESERVE WHITESPACE option.
 *
 */
xmlPreserveWhitespace
xmlPreserveWhitespace ::=
| <STRIP> <WHITESPACE>
| <PRESERVE> <WHITESPACE>

/*
 * xmlSerializeValue
 *
 * Syntax is as follows:
 *
 *   XMLSERIALIZE(  AS  )
 *
 * The result of this operation will be a string value with the type specified
 * by the user.  For example:
 *
 * ij> SELECT id, XMLSERIALIZE(xdoc AS varchar(30)) FROM x_table;
 * ID         |2
 * ------------------------------------------
 * 1          | doc 
 *
 */
xmlSerializeValue
xmlSerializeValue ::= additiveExpression xmlSerializeTargetType

/*
 * xmlSerializeTargetType
 *
 * Parse the target type of an XMLSERIALIZE operation.
 *
 */
xmlSerializeTargetType
xmlSerializeTargetType ::=
| <AS> dataTypeDDL

/*
 * xmlQueryValue
 *
 * This method is used for parsing the XMLEXISTS and XMLQUERY operators
 * (which operator depends on the received boolean parameter).
 *
 * For XMLEXISTS, the syntax is as follows:
 *
 *   XMLEXISTS(  PASSING BY REF  )
 *
 * The result of this operation will be a boolean true/false/unknown value:
 *   -- Unknown if either  or  is null;
 *   -- True if evaluation of the given query expression against the
 *      given xml-value returns at least one node.
 *   -- False otherwise.
 *
 * For example:
 *
 * ij> SELECT id FROM x_table WHERE XMLEXISTS('/simple' PASSING BY REF xdoc);
 * ID
 * -----------
 * 1
 *
 * ====
 *
 * For XMLQUERY, the syntax is as follows:
 *
 *   XMLQUERY( 
 *      PASSING BY REF 
 *      [ RETURNING SEQUENCE [ BY REF ] ]
 *      EMPTY ON EMPTY
 *   )
 *
 * The result of this operation will be an XMLDataValue.
 *
 * For example:
 *
 * ij> SELECT XMLSERIALIZE(
 *       XMLQUERY('/simple' PASSING BY REF xdoc EMPTY ON EMPTY) AS CHAR(100));
 * ID
 * -----------
 *  doc 
 *
 */
xmlQueryValue
xmlQueryValue ::= additiveExpression <PASSING> xmlPassingMechanism xqVarList ( ( xqReturningClause ( xmlPassingMechanism )? )? xqEmptyHandlingClause | )

/**
 * xqVarList
 *
 * Parse a list of XML query variables, which can include at most one
 * XML value to be used as the "context item" for the query.  If
 * such a context item was found, return that item; for all other
 * variable declarations we currently throw a "not supported" error
 * because Xalan doesn't allowing binding of variables.
 */
xqVarList
xqVarList ::= xqVariable ( <COMMA> xqVariable )*

/**
 * xqVariable
 *
 * Parse an XML query variable.  If the argument is an XML value
 * to be used as the "context item" for a query, then store the
 * value in the first slot of the received ValueNode array;
 * otherwise, throw a "not supported" errror (for now).
 */
xqVariable
xqVariable ::= additiveExpression ( <AS> identifier )? ( ( xmlPassingMechanism )? )

/*
 * xmlPassingMechanism
 *
 * For now, we only support the BY REF option because
 * that gives us better performance (allows us to avoid
 * performing potentially deep copies of XML nodes).  This
 * means that if the same XML value is passed BY REF into
 * two different XML arguments for a single operator, then
 * every node in the first XML argument must have an
 * identical node in the second XML argument, and the
 * ids for both nodes must be the same.  That said,
 * since we don't support variable binding yet, this
 * becomes a non-issue because we can't pass XML values.
 * In the future, though, we may choose to support the
 * passing/binding of variables (the only reason we
 * don't now is because Xalan doesn't support it) and
 * if we do, BY REF should provide better performance
 * due to lack of deep copying.
 */
xmlPassingMechanism
xmlPassingMechanism ::= <BY> <REF>
| <BY> <VALUE>

/*
 * xqReturningClause
 *
 * For now we only support "RETURNING SEQUENCE".  The reason
 * is that this applies to the XMLQUERY operator and the
 * results of evaluating a query expression in Xalan against
 * an XML value can be an arbritary sequence of items--including
 * atomic values.  For simplicity we just return the values
 * as they are, without doing any further work.  SQL/XML[2006]
 * says that if we supported RETURNING CONTENT then we'd have
 * to construct an XQuery document from the results--but we don't
 * do that extra work for now, so we just say that we return
 * SEQUENCE.
 *
 * NOTE: This means that we may not be able to store the results
 * of an XMLQUERY operation into a Derby XML column.  Right now
 * an XML column can only hold valid DOCUMENT nodes, which we
 * we define as an XML value whose serialized form can be parsed
 * by a JAXP DocumentBuilder (because that's what Derby's XMLPARSE
 * operator uses and the result is always a Document node).
 * Internally this means that we can only store a sequence if it
 * contains exactly one org.w3c.dom.Node that is an instance of
 * org.w3c.dom.Document.  If the result of an XMLQUERY operation
 * does not fit this criteria then it will *not* be storable into
 * Derby XML columns.
 */
xqReturningClause
xqReturningClause ::= <RETURNING> <SEQUENCE>
| <RETURNING> <CONTENT>

/*
 * xqEmptyHandlingClause
 *
 * Defines what the behavior should be when an XMLQUERY operator
 * results in an empty sequence.  For now we just return the
 * empty sequence.
 */
xqEmptyHandlingClause
xqEmptyHandlingClause ::= <EMPTY> <ON> <EMPTY>
| <NULL> <ON> <EMPTY>

/*
 * numericFunctionType
 */
numericFunctionType
numericFunctionType ::= doubleType
| exactIntegerType

/*
 * dateTimeScalarFunction
 */
dateTimeScalarFunction
dateTimeScalarFunction ::= <TIME> <LEFT_PAREN> additiveExpression <RIGHT_PAREN>
| <DATE> <LEFT_PAREN> additiveExpression <RIGHT_PAREN>
| <TIMESTAMP> <LEFT_PAREN> additiveExpression timestampFunctionCompletion
| datetimeField <LEFT_PAREN> additiveExpression <RIGHT_PAREN>

/*
 * timestampFunctionCompletion
 */
timestampFunctionCompletion
timestampFunctionCompletion ::= <RIGHT_PAREN>
| <COMMA> additiveExpression <RIGHT_PAREN>

/*
 * booleanLiteral
 */
booleanLiteral
booleanLiteral ::= <TRUE>
| <FALSE>

/*
 * generalValueSpecification
 */
generalValueSpecification
generalValueSpecification ::= dynamicParameterSpecification
| userNode
| currentRoleNode



userNode
userNode ::= <USER>
| <CURRENT_USER>
| <SESSION_USER>

/*
 * currentRoleNode
 */
currentRoleNode
currentRoleNode ::= <CURRENT_ROLE>

/*
 * newInvocation
 */
newInvocation
newInvocation ::= <NEW> javaClassName methodCallParameterList

/*
 * vtiTableConstruct
 *
 * Parse a TABLE() constructor that corresponds to an internal
 * VTI invocation.  For example:
 *
 *    TABLE (  (arg1, arg2, ...) )
 *
 * where  is a table name that Derby will map internally
 * to a VTI (ex. "SYSCS_DIAG.SPACE_TABLE").  The list of arguments
 * will then be passed to the VTI when it is invoked (DERBY-2152).
 *
 * An example query where this might occur is as follows:
 *
 *   SELECT * FROM TABLE(SYSCS_DIAG.SPACE_TABLE('APP', 'T1')) x
 *
 * in which case SYSCS_DIAG.SPACE_TABLE will be mapped (internally)
 * to the "org.apache.derby.diag.SpaceTable" diagnostic VTI.  Thus
 * the equivalent call prior to DERBY-2152 would have been:
 *
 *   SELECT * FROM NEW org.apache.derby.diag.SpaceTable('APP', 'T1')) x
 *
 * Note that this latter syntax is still supported.
 */
vtiTableConstruct
vtiTableConstruct ::= <TABLE> <LEFT_PAREN> qualifiedName methodCallParameterList <RIGHT_PAREN>

/*
 * staticMethodInvocation
 */
staticMethodInvocation
staticMethodInvocation ::= staticMethodName methodCallParameterList

/**
 * methodCallParameterList
*/
methodCallParameterList
methodCallParameterList ::= <LEFT_PAREN> ( methodParameter ( <COMMA> methodParameter )* )? <RIGHT_PAREN>

/*
 * routineInvocation
 */
routineInvocation
routineInvocation ::= routineExpression
| distinctUDA

/*
 * routineExpression
 */
routineExpression
routineExpression ::= qualifiedName methodCallParameterList

/*
 * distinctUDA
 */
distinctUDA
distinctUDA ::= qualifiedName <LEFT_PAREN> <DISTINCT> additiveExpression <RIGHT_PAREN>

/*
 * javaClass
 */
javaClass
javaClass ::= javaClassName

/*
 * columnMethodInvocation
 */
columnMethodInvocation
columnMethodInvocation ::= columnNameForInvocation nonStaticMethodInvocation

/*
 * columnNameForInvocation
 */
columnNameForInvocation
columnNameForInvocation ::= identifier ( <PERIOD> identifier ( <PERIOD> identifier )? )?

/*
 * columnReference
 */
columnReference
columnReference ::= identifier ( <PERIOD> identifier ( <PERIOD> identifier )? )?

/*
void
columnReference() throws StandardException :
{}
{
	/*
	**
	** I re-wrote the above rule because it caused a grammar ambiguitity.
	** The problem is that we are parsing a dot-separated list of identifiers,
	** and the grammar doesn't know what the identifiers stand for, but the
	** syntax assumed that it did.  For example, in schema.table.column,
	** the grammar doesn't know when it parses the first identifier whether
	** it will be a catalog name, schema name, table name, or column name.
	**
	** I think this problem could be solved by increasing the lookahead.
	** I will try that solution next.  I like that solution better because,
	** if it works, it will be easier for the grammar to figure out what
	** each identifier stands for.
	**

	[    |
	  [ [ [   ]   ]   ]
	]
	
}
*/
orderByClause
orderByClause ::= <ORDER> <BY> sortSpecificationList



atIsolationLevel
atIsolationLevel ::= <WITH> isolationLevelDB2Abbrev



sortSpecificationList
sortSpecificationList ::= sortSpecification ( <COMMA> sortSpecification )*



sortSpecification
sortSpecification ::= sortKey ( orderingSpecification )? ( nullOrdering )?



sortKey
sortKey ::= additiveExpression



orderingSpecification
orderingSpecification ::= <ASC>
| <DESC>

/*
 * The data type comparison functions need to know whether NULL values
 * should sort higher than non-NULL values, or lower. The answer to this
 * depends on whether the user specified ASCending or DESCending, and on
 * whether the user specified NULLS FIRST, or NULLS LAST, as follows:
 *
 * +===============+========+========+
 * | ORDER BY says | ASC    | DESC   |
 * +===============+========+========+
 * | NULLS FIRST   | less   | greater|
 * +===============+========+========+
 * | NULLS LAST    | greater| less   |
 * +===============+========+========+
 */
nullOrdering
nullOrdering ::= <NULLS> <LAST>
| <NULLS> <FIRST>

/*
 * offsetFetchFirstClause
 */
offsetFetchFirstClause
offsetFetchFirstClause ::= sqlStandardOffsetFetchFirst
| ( jdbcLimitOffset )?

/*
 * sqlStandardOffsetFetchFirst
 */
sqlStandardOffsetFetchFirst
sqlStandardOffsetFetchFirst ::= ( offsetClause )? ( fetchFirstClause )?

/*
 * jdbcLimitOffset
 */
jdbcLimitOffset
jdbcLimitOffset ::= <LEFT_BRACE> <LIMIT> ( intLiteral | dynamicParameterSpecification ) ( <OFFSET> ( intLiteral | dynamicParameterSpecification ) )? <RIGHT_BRACE>

/*
 * offsetClause
 */
offsetClause
offsetClause ::= <OFFSET> ( intLiteral | dynamicParameterSpecification ) ( <ROW> | <ROWS> )

/*
 * fetchFirstClause
 */
fetchFirstClause
fetchFirstClause ::= <FETCH> ( <FIRST> | <NEXT> ) ( intLiteral | dynamicParameterSpecification )? ( <ROW> | <ROWS> ) <ONLY>

/*
 * forUpdateClause
 */
forUpdateClause
forUpdateClause ::= <UPDATE> ( <OF> forUpdateColumnList )?
| <READ> <ONLY>
| <FETCH> <ONLY>

/*
 * forUpdateColumnList
 */
forUpdateColumnList
forUpdateColumnList ::= forUpdateColumn ( <COMMA> forUpdateColumn )*

/*
 * forUpdateColumn
 */
forUpdateColumn
forUpdateColumn ::= identifier

/*
 * setClauseList
 */
setClauseList
setClauseList ::= setClause ( <COMMA> setClause )*

/*
 * setClause
 */
setClause
setClause ::= columnReference <EQUALS_OPERATOR> updateSource

/*
 * updateSource
 */
updateSource
updateSource ::= valueExpression
| nullSpecification
| <_DEFAULT>

/*
 * nullSpecification
 */
nullSpecification
nullSpecification ::= <NULL>

/*
 * insertColumnsAndSource
 */
insertColumnsAndSource
insertColumnsAndSource ::= ( <LEFT_PAREN> insertColumnList <RIGHT_PAREN> )? ( propertyList <CHECK_PROPERTIES> )? queryExpression ( orderByClause )? offsetFetchFirstClause

/*
 * insertColumnList
 */
insertColumnList
insertColumnList ::= columnQualifiedNameList

/*
 * columnQualifiedNameList
 */
columnQualifiedNameList
columnQualifiedNameList ::= columnQualifiedNameItem ( <COMMA> columnQualifiedNameItem )*

/*
 * columnQualifiedNameItem
 */
columnQualifiedNameItem
columnQualifiedNameItem ::= columnReference

/*
 * rowValueConstructor
 */
rowValueConstructor
rowValueConstructor ::= <LEFT_PAREN> rowValueConstructorList <RIGHT_PAREN>
| rowValueConstructorElement

/*
 * rowValueConstructorElement
 */
rowValueConstructorElement
rowValueConstructorElement ::= valueExpression
| nullSpecification
| <_DEFAULT>
|

/*
 * rowValueConstructorList
 */
rowValueConstructorList
rowValueConstructorList ::= rowValueConstructorElement ( <COMMA> rowValueConstructorElement )*

/*
 * tableSubquery
 */
tableSubquery
tableSubquery ::= subquery

/*
 * subquery
 */
subquery
subquery ::= queryExpression ( orderByClause )? offsetFetchFirstClause

/*
 * inPredicateValue
 */
inPredicateValue
inPredicateValue ::= <LEFT_PAREN> ( tableSubquery | inValueList ) <RIGHT_PAREN>

/*
 * inValueList
 */
inValueList
inValueList ::= inElement ( <COMMA> inElement )*

/*
 * inElement
 */
inElement
inElement ::= additiveExpression

/*
 * quantifier
 */
quantifier
quantifier ::= <ALL>
| some

/*
 * some
 */
some
some ::= <SOME>
| <ANY>

/*
 * existsExpression
 */
existsExpression
existsExpression ::= <EXISTS> <LEFT_PAREN> tableSubquery <RIGHT_PAREN>

/*
 * tableExpression
 */
tableExpression
tableExpression ::= fromClause ( <WHERE> whereClause )? ( groupByClause )? ( havingClause )? ( windowClause )? ( optimizerOverridePlan )?

/*
 * fromClause
 */
fromClause
fromClause ::= <FROM> ( fromListProperties )? dummyTableReferenceRule ( <COMMA> dummyTableReferenceRule )*

/*
 * fromListProperties
 */
fromListProperties
fromListProperties ::= propertyList <CHECK_PROPERTIES>

/* This rule created simply as a way to add the result of tableReference()
 * to the fromList.
 */
dummyTableReferenceRule
dummyTableReferenceRule ::= <TABLE> tableReferenceTypes
| tableReferenceTypes



tableReferenceTypes
tableReferenceTypes ::= tableReference
| <LEFT_BRACE> <OJ> tableReference <RIGHT_BRACE>



optionalTableClauses
optionalTableClauses ::= optionalTableProperties
| ( ( <AS> )? identifier ( <LEFT_PAREN> derivedColumnList <RIGHT_PAREN> )? ( propertyList <CHECK_PROPERTIES> )? )?



optionalTableProperties
optionalTableProperties ::= propertyList <CHECK_PROPERTIES>

/*
 * tableReference
 */
tableReference
tableReference ::= tableFactor ( joinedTableExpression )*



tableFactor
tableFactor ::= ( newInvocation | vtiTableConstruct ) ( <AS> )? identifier ( <LEFT_PAREN> derivedColumnList <RIGHT_PAREN> )? ( optionalTableProperties )?
| qualifiedName optionalTableClauses
| derivedTable ( <AS> )? identifier ( <LEFT_PAREN> derivedColumnList <RIGHT_PAREN> )? ( optionalTableProperties )?
| <LEFT_PAREN> tableReferenceTypes <RIGHT_PAREN>

/*
 * derivedColumnList
 */
derivedColumnList
derivedColumnList ::= columnNameList

/*
 * columnNameList
 */
columnNameList
columnNameList ::= columnNameItem ( <COMMA> columnNameItem )*

/*
 * columnNameItem
 */
columnNameItem
columnNameItem ::= identifier

/*
 * indexColumnList
 */
indexColumnList
indexColumnList ::= indexColumnItem ( <COMMA> indexColumnItem )*

/*
 * indexColumnItem
 */
indexColumnItem
indexColumnItem ::= identifier ( <ASC> | <DESC> )?

/*
 * derivedTable
 */
derivedTable
derivedTable ::= <LEFT_PAREN> tableSubquery <RIGHT_PAREN>



joinedTableExpression
joinedTableExpression ::= crossJoin
| qualifiedJoin
| naturalJoin



crossJoin
crossJoin ::= <CROSS> <JOIN> tableFactor



qualifiedJoin
qualifiedJoin ::= ( joinType )? <JOIN> tableReferenceTypes joinSpecification



naturalJoin
naturalJoin ::= <NATURAL> ( joinType )? <JOIN> tableFactor



joinType
joinType ::= <INNER>
| outerJoinType ( <OUTER> )?



outerJoinType
outerJoinType ::= <LEFT>
| <RIGHT>



joinSpecification
joinSpecification ::= joinCondition
| namedColumnsJoin



joinCondition
joinCondition ::= <ON> valueExpression



namedColumnsJoin
namedColumnsJoin ::= <USING> <LEFT_PAREN> columnNameList <RIGHT_PAREN>

/*
 * tableValueConstructor
 */
tableValueConstructor
tableValueConstructor ::= <VALUES> tableValueConstructorList

/*
 * tableValueConstructorList
 */
tableValueConstructorList
tableValueConstructorList ::= rowValueConstructor ( <COMMA> rowValueConstructor )*

/*
 * explicitTable
 */

/*
 * datetimeValueFunction
 */
datetimeValueFunction
datetimeValueFunction ::= <CURRENT> <DATE>
| <CURRENT_DATE>
| <CURRENT> <TIME>
| <CURRENT_TIME>
| <CURRENT> <TIMESTAMP>
| <CURRENT_TIMESTAMP>

/*
** Note that set function and aggregate are used
** interchangeably in the parser.  The tree has
** aggregate nodes.
*/
windowOrAggregateFunctionNode
windowOrAggregateFunctionNode ::= <COUNT> <LEFT_PAREN> ( <ASTERISK> | aggregateExpression ) <RIGHT_PAREN> ( overClause )?
| generalAggregate ( overClause )?
| <ROWNUMBER> <LEFT_PAREN> <RIGHT_PAREN> overClause



overClause
overClause ::= <OVER> ( <LEFT_PAREN> ( orderByClause )? <RIGHT_PAREN> | identifier )



aggregateExpression
aggregateExpression ::= ( setQuantifier )? additiveExpression



generalAggregate
generalAggregate ::= builtInAggregateType <LEFT_PAREN> aggregateExpression <RIGHT_PAREN>

/*
** All built in aggregates are pretty similar to user
** defined aggregates, except we know what to map to
** without looking up the class name.
**
** NOTE: COUNT is omitted here because the COUNT aggregate is
** factored into a different rule, to distinguish between
** COUNT(*) and COUNT().
*/
builtInAggregateType
builtInAggregateType ::= ( <MAX> | <AVG> | <MIN> | <SUM> )



castSpecification
castSpecification ::= <CAST> <LEFT_PAREN> castOperand <AS> dataTypeCast <RIGHT_PAREN>

/**
 * Next value from a sequence object
 */
nextValueExpression
nextValueExpression ::= <NEXT> <VALUE> <FOR> qualifiedName

/*
 * charOrVarchar
 */
charOrVarchar
charOrVarchar ::= <CHAR>
| <VARCHAR>



castOperand
castOperand ::= additiveExpression
| <NULL>

/*
 * dynamicParameterSpecification
 */
dynamicParameterSpecification
dynamicParameterSpecification ::= <QUESTION_MARK>

/*
 * whereClause
 */
whereClause
whereClause ::= valueExpression



groupByClause
groupByClause ::= <GROUP> <BY> ( <ROLLUP> <LEFT_PAREN> groupingColumnReferenceList <RIGHT_PAREN> | groupingColumnReferenceList )



groupingColumnReferenceList
groupingColumnReferenceList ::= groupingColumnReference ( <COMMA> groupingColumnReference )*



groupingColumnReference
groupingColumnReference ::= additiveExpression



havingClause
havingClause ::= <HAVING> valueExpression



windowClause
windowClause ::= <WINDOW> windowDefinition ( <COMMA> windowDefinition )*



windowDefinition
windowDefinition ::= identifier <AS> <LEFT_PAREN> ( orderByClause )? <RIGHT_PAREN>

/*
 * optimizerOverridePlan
 */
optimizerOverridePlan
optimizerOverridePlan ::= <DERBYPLAN> optimizerPlan

/*
 * optimizerPlan
 */
optimizerPlan
optimizerPlan ::= optimizerJoin
| optimizerRowSource

/*
 * optimizerJoin
 */
optimizerJoin
optimizerJoin ::= <LEFT_PAREN> optimizerPlan joinStrategy optimizerPlan <RIGHT_PAREN>

/*
 * joinStrategy
 */
joinStrategy
joinStrategy ::= <ASTERISK>
| <HASH>

/*
 * optimizerRowSource
 */
optimizerRowSource
optimizerRowSource ::= qualifiedName ( <LEFT_PAREN> <RIGHT_PAREN> )?



schemaDefinition
schemaDefinition ::= <SCHEMA> ( identifier ( <AUTHORIZATION> identifier )? | <AUTHORIZATION> identifier )

/*
 * roleDefinition
 */
roleDefinition
roleDefinition ::= <ROLE> identifier

/*
 * sequenceDefinition
 */
sequenceDefinition
sequenceDefinition ::= <SEQUENCE> qualifiedName ( sequenceGeneratorOption )*

/*
 * sequenceGeneratorOption
 */
sequenceGeneratorOption
sequenceGeneratorOption ::= ( <AS> exactIntegerType | <START> <WITH> exactIntegerObject | <INCREMENT> <BY> exactIntegerObject | ( ( <MAXVALUE> exactIntegerObject ) | ( <NO> <MAXVALUE> ) ) | ( ( <MINVALUE> exactIntegerObject ) | ( <NO> <MINVALUE> ) ) | cycleClause )

/*
 * cycleClause
 */
cycleClause
cycleClause ::= <CYCLE>
| <NO> <CYCLE>

/*
 * exactNumberObject
 */
exactIntegerObject
exactIntegerObject ::= exactNumber

/*
 * stepValue
 */
stepValue
stepValue ::= <INCREMENT> <BY> exactNumber

/*
 * dropSequenceStatement
 */
dropSequenceStatement
dropSequenceStatement ::= <SEQUENCE> qualifiedName <RESTRICT>

/*
 * tableDefinition
 */
tableDefinition
tableDefinition ::= <TABLE> qualifiedName ( tableElementList ( propertyList <CHECK_PROPERTIES> )? | ( <LEFT_PAREN> tableColumnList <RIGHT_PAREN> )? <AS> queryExpression <WITH> ( <NO> )? <DATA> )



tableColumnList
tableColumnList ::= columnNameList

/*
 * This method is called when a comment starting with "--derby-properties" is
 * found.  Such a comment is a special directive to Derby and allows an SQL
 * statement to pass optimizer overrides. Derby looks for
 *
 *     propertyName = value* [, propertyName = value]*
 *
 * after "--derby-properties" and returns these properties in a Properties
 * object as a return value of this method.  If the parameter
 * "propertiesUseAllowed" is true, it indicates that users are allowed to
 * specify optimizer overrides in the given context.  False means optimizer
 * overrides in the given context are allowed internally only, e.g. by the
 * class org.apache.derby.impl.load.Import specifies the property
 * "insertMode=replace/bulkInsert" in the INSERT statement. This same property
 * will not be acceptable from an INSERT statement from a user SQL statement.
 */
propertyList
propertyList ::= <DERBYDASHPROPERTIES>

/*
 * DB2lockGranularityClause
 */
DB2lockGranularityClause
DB2lockGranularityClause ::= <LOCKSIZE> lockGranularity

/*
 * lockGranularity
 */
lockGranularity
lockGranularity ::= <TABLE>
| <ROW>

/*
 * indexDefinition
 */
indexDefinition
indexDefinition ::= ( unique )? <INDEX> qualifiedName <ON> qualifiedName <LEFT_PAREN> indexColumnList <RIGHT_PAREN> ( propertyList <CHECK_PROPERTIES> )?

/*
 * unique
 */
unique
unique ::= <UNIQUE>

/**
	CREATE PROCEDURE

	procedureElements contains the description of the procedure.
	(CREATE FUNCTIONS shares this lyout), see functionDefinition

	0 - Object[] 3 element array for parameters
	1 - TableName - specific name
	2 - Integer - dynamic result set count
	3 - String language (always java) - ignore
	4 - String external name (also passed directly to create alias node - ignore
	5 - Short parameter style (always java) - ignore 
	6 - Short - SQL allowed.
	7 - Boolean - CALLED ON NULL INPUT (always TRUE for procedures)
	8 - TypeDescriptor - return type (always NULL for procedures)
*/
procedureDefinition
procedureDefinition ::= <PROCEDURE> qualifiedName procedureParameterList ( routineElement )+



routineElement
routineElement ::= ( <SPECIFIC> qualifiedName | ( <DYNAMIC> )? <RESULT> <SETS> uint_value | <LANGUAGE> <JAVA> | <DETERMINISTIC> | <NOT> <DETERMINISTIC> | <EXTERNAL> ( <NAME> string | <SECURITY> ) | <PARAMETER> <STYLE> parameterStyle | <NO> <SQL> | <CONTAINS> <SQL> | <READS> <SQL> <DATA> | <MODIFIES> <SQL> <DATA> | calledOnNullInput )



calledOnNullInput
calledOnNullInput ::= ( <CALLED> | <RETURNS> <NULL> ) <ON> <NULL> <INPUT>



routineSecurityClause
routineSecurityClause ::= ( <INVOKER> | <DEFINER> )



parameterStyle
parameterStyle ::= <JAVA>
| <DERBY_JDBC_RESULT_SET>
| <DERBY>



procedureParameterList
procedureParameterList ::= <LEFT_PAREN> ( procedureParameterDefinition ( <COMMA> procedureParameterDefinition )* ( ellipsis )? )? <RIGHT_PAREN>

/*
 * procedureParameterDefinition
 */
procedureParameterDefinition
procedureParameterDefinition ::= inoutParameter ( identifier )? dataTypeDDL



inoutParameter
inoutParameter ::= ( <IN> | <OUT> | <INOUT> )?

/**
	CREATE FUNCTION

	functionElements contains the description of the function.

	0 - Object[] 3 element array for parameters
	1 - TableName - specific name
	2 - Integer - dynamic result set count - always 0
	3 - String language (always java) - required to be set
	4 - String external name (also passed directly to create alias node - ignore
	5 - Short parameter style (always java) - required to be set 
	6 - Short - SQL allowed.
	7 - Boolean - CALLED ON NULL INPUT
	8 - TypeDescriptor - return type
*/
functionDefinition
functionDefinition ::= <FUNCTION> qualifiedName functionParameterList <RETURNS> functionReturnDataType ( routineElement )+



functionParameterList
functionParameterList ::= <LEFT_PAREN> ( functionParameterDefinition ( <COMMA> functionParameterDefinition )* ( ellipsis )? )? <RIGHT_PAREN>



ellipsis
ellipsis ::= <ELLIPSIS>

/*
 * functionParameterDefinition
 */
functionParameterDefinition
functionParameterDefinition ::= ( identifier )? dataTypeDDL

/*
 * functionReturnDataType
 */
functionReturnDataType
functionReturnDataType ::= ( catalogType | functionTableType )

/*
 * functionTableType
 */
functionTableType
functionTableType ::= <TABLE> <LEFT_PAREN> functionTableReturnColumn ( <COMMA> functionTableReturnColumn )* <RIGHT_PAREN>

/*
 * functionTableReturnColumn
 */
functionTableReturnColumn
functionTableReturnColumn ::= identifier dataTypeDDL

/**
	CREATE TYPE
*/
udtDefinition
udtDefinition ::= <TYPE> qualifiedName <EXTERNAL> <NAME> string <LANGUAGE> <JAVA>



aggregateDefinition
aggregateDefinition ::= <DERBY> <AGGREGATE> qualifiedName <FOR> dataTypeDDL ( <RETURNS> dataTypeDDL )? <EXTERNAL> <NAME> string



viewDefinition
viewDefinition ::= <VIEW> qualifiedName ( <LEFT_PAREN> viewColumnList <RIGHT_PAREN> )? <AS> queryExpression ( orderByClause )? offsetFetchFirstClause



viewColumnList
viewColumnList ::= columnNameList



triggerDefinition
triggerDefinition ::= <TRIGGER> qualifiedName beforeOrAfter triggerEvent <ON> qualifiedName ( triggerReferencingClause )? ( <FOR> <EACH> rowOrStatement )? ( <MODE> <DB2SQL> )? ( <WHEN> <LEFT_PAREN> valueExpression <RIGHT_PAREN> )? proceduralStatement



synonymDefinition
synonymDefinition ::= <SYNONYM> qualifiedName <FOR> qualifiedName



beforeOrAfter
beforeOrAfter ::= <NO> <CASCADE> <BEFORE>
| <AFTER>



triggerEvent
triggerEvent ::= <INSERT>
| <DELETE>
| <UPDATE> ( <OF> columnNameList )?



rowOrStatement
rowOrStatement ::= <ROW>
| <STATEMENT>



triggerReferencingClause
triggerReferencingClause ::= <REFERENCING> triggerReferencingExpression ( triggerReferencingExpression )*



triggerReferencingExpression
triggerReferencingExpression ::= ( <NEW> ( <ROW> | <TABLE> )? | <OLD> ( <ROW> | <TABLE> )? | <NEW_TABLE> | <OLD_TABLE> ) <AS> identifier

/*
 * defaultClause
 */
defaultClause
defaultClause ::= ( <WITH> )? <_DEFAULT> defaultOption
| generatedColumnOption

/*
 * defaultNullOnlyClause
 */
defaultNullOnlyClause
defaultNullOnlyClause ::= <_DEFAULT> <NULL>

/*
 * generatedColumnOption
 */

//ToCleanUp
//A specific class not such long[] should exists for autoIncrementInfo ...
generatedColumnOption
generatedColumnOption ::= <GENERATED> ( generatedAlways | generatedByDefault )

/*
 * generatedAlways
 */
generatedAlways
generatedAlways ::= <ALWAYS> ( asIdentity | generationClause )

/*
 * generatedByDefault
 */
generatedByDefault
generatedByDefault ::= <BY> <_DEFAULT> asIdentity

/*
 * asIdentity
 */
asIdentity
asIdentity ::= <AS> <IDENTITY> ( <LEFT_PAREN> autoIncrementBeginEnd <RIGHT_PAREN> )?

/*
 * generationClause
 */
generationClause
generationClause ::= <AS> <LEFT_PAREN> valueExpression <RIGHT_PAREN>

/*
 * autoIncrementBeginEnd
 */
autoIncrementBeginEnd
autoIncrementBeginEnd ::= ( ( identityColumnOption )* )

/*
 * identityColumnOption
 */
identityColumnOption
identityColumnOption ::= ( <START> <WITH> exactNumber | <INCREMENT> <BY> exactNumber | <CYCLE> | <NO> <CYCLE> | <COMMA> ( | ) )

/*
 * whetherCycle
 */
whetherCycle
whetherCycle ::=

/*
 * defaultOption
 */
defaultOption
defaultOption ::= <NULL>
| DB2DefaultOption

/*
 * DB2DefaultOption
 */
DB2DefaultOption
DB2DefaultOption ::= <CURRENT> ( <SCHEMA> | <SQLID> )
| userNode
| currentRoleNode
| miscBuiltins
| miscBuiltins
| datetimeValueFunction
| literal

/*
 * literal
 */
literal
literal ::= ( sign )? numericLiteral
| stringLiteral
| hexLiteral
| dateTimeLiteral
| booleanLiteral

/*
 * intLiteral
 */
intLiteral
intLiteral ::= ( sign )? <EXACT_NUMERIC>

/*
 * numericLiteral
 */
numericLiteral
numericLiteral ::= <EXACT_NUMERIC>
| <APPROXIMATE_NUMERIC>

/*
 * dateTimeLiteral
 */
dateTimeLiteral
dateTimeLiteral ::= ( ( <LEFT_BRACE> escapedDateTimeLiteral <RIGHT_BRACE> ) )

/*
 * escapedDateTimeLiteral
 */
escapedDateTimeLiteral
escapedDateTimeLiteral ::= <D> bareDateLiteral
| <T> bareTimeLiteral
| <TS> bareTimestampLiteral

/*
 * bareDateLiteral
 */
bareDateLiteral
bareDateLiteral ::= string

/*
 * bareTimeLiteral
 */
bareTimeLiteral
bareTimeLiteral ::= string

/*
 * bareTimestampLiteral
 */
bareTimestampLiteral
bareTimestampLiteral ::= string

/*
 * string
 */
string
string ::= <STRING>

/*
 * stringLiteral
 */
stringLiteral
stringLiteral ::= <STRING>

/*
 * hexLiteral
 */
hexLiteral
hexLiteral ::= <HEX_STRING>



constraintNameDefinition
constraintNameDefinition ::= <CONSTRAINT> qualifiedName

/*
 * DB2 requires column check constraints to refer to only that column. Derby
 * doesn't care if check constraints are column level or table level. For DB2 compatibility
 * check that column check constraints only refer to that column.
 */
checkConstraintDefinition
checkConstraintDefinition ::= <CHECK> <LEFT_PAREN> valueExpression <RIGHT_PAREN>

/*
 * spsRenameStatement
 */
spsRenameStatement
spsRenameStatement ::= <RENAME> ( renameTableStatement | renameIndexStatement | renameColumnStatement )

/*
 * renameTableStatement
 */
renameTableStatement
renameTableStatement ::= <TABLE> qualifiedName <TO> identifier

/*
 * renameIndexStatement
 */
renameIndexStatement
renameIndexStatement ::= <INDEX> identifier <TO> identifier



renameColumnStatement
renameColumnStatement ::= <COLUMN> columnReference <TO> identifier



lockStatement
lockStatement ::= <LOCK> <TABLE> qualifiedName <IN> lockMode <MODE>



lockMode
lockMode ::= <EXCLUSIVE>
| <SHARE>



execStatement
execStatement ::= <EXECUTE> <STATEMENT> qualifiedName



setIsolationStatement
setIsolationStatement ::= setIsolationHeader ( ( <EQUALS_OPERATOR> | <TO> ) )? transactionMode



setIsolationHeader
setIsolationHeader ::= <ISOLATION>
| <CURRENT> <ISOLATION>



transactionMode
transactionMode ::= isolationLevelDB2OrReset



isolationLevelDB2OrReset
isolationLevelDB2OrReset ::= ( <RESET> | isolationLevelDB2 )



isolationLevelDB2
isolationLevelDB2 ::= ( isolationLevelDB2Abbrev | ( ( <REPEATABLE> <READ> ) | <SERIALIZABLE> ) | <CURSOR> <STABILITY> | <DIRTY> <READ> | <READ> <COMMITTED> | <READ> <UNCOMMITTED> )



isolationLevelDB2Abbrev
isolationLevelDB2Abbrev ::= ( <RR> | <RS> | <CS> | <UR> )



isolationLevel
isolationLevel ::= <ISOLATION> <LEVEL> levelOfIsolation



levelOfIsolation
levelOfIsolation ::= <READ>
| <REPEATABLE> <READ>
| <SERIALIZABLE>



levelOfIsolationRead
levelOfIsolationRead ::= <UNCOMMITTED>
| <COMMITTED>

/*
 * simpleValueSpecification
 */
simpleValueSpecification
simpleValueSpecification ::= literal

/*
 * setRoleStatement
 */
setRoleStatement
setRoleStatement ::= <ROLE> setRoleSpecification

/*
 * setRoleSpecification
 */
setRoleSpecification
setRoleSpecification ::= <NONE>
| identifier
| dynamicParameterSpecification
| string



setSchemaStatement
setSchemaStatement ::= setSchemaHeader ( <EQUALS_OPERATOR> )? setSchemaValues



setSchemaHeader
setSchemaHeader ::= <SCHEMA>
| <CURRENT> ( <SCHEMA> | <SQLID> )



setSchemaValues
setSchemaValues ::= identifier
| <USER>
| dynamicParameterSpecification
| string

// Set the locale for messages coming from the database system. This
// is for support only, so we can get messages in our preferred language
// (usually English). I didn't want to create all the execution wiring
// to do this, so this command executes in the parser
setMessageLocaleStatement
setMessageLocaleStatement ::= <MESSAGE_LOCALE> string

/*
 * valueSpecification
 */
valueSpecification
valueSpecification ::= literal
| generalValueSpecification
| <NULLIF> <LEFT_PAREN> valueExpression <COMMA> valueExpression <RIGHT_PAREN>
| <CASE> searchedCaseExpression
| <CASE> valueExpression simpleCaseExpression



searchedCaseExpression
searchedCaseExpression ::= ( whenThenExpression )+ ( <ELSE> thenElseExpression )? <END>

/*
 * whenThenExpression
 */
whenThenExpression
whenThenExpression ::= <WHEN> valueExpression <THEN> thenElseExpression

/*
 * thenElseExpression
 */
thenElseExpression
thenElseExpression ::= <NULL>
| valueExpression



simpleCaseExpression
simpleCaseExpression ::= ( simpleWhenClause )+ ( <ELSE> thenElseExpression )? <END>



simpleWhenClause
simpleWhenClause ::= <WHEN> whenOperandList <THEN> thenElseExpression



whenOperandList
whenOperandList ::= whenOperand ( <COMMA> whenOperandList )?



whenOperand
whenOperand ::= remainingPredicate
| valueExpression



tableConstraintDefinition
tableConstraintDefinition ::= ( constraintNameDefinition )? tableConstraint ( propertyList <CHECK_PROPERTIES> )?



tableConstraint
tableConstraint ::= ( uniqueConstraintDefinition | referentialConstraintDefinition | checkConstraintDefinition ) ( constraintCharacteristics )?



uniqueConstraintDefinition
uniqueConstraintDefinition ::= uniqueSpecification <LEFT_PAREN> uniqueColumnList <RIGHT_PAREN>

//the second parameter to the following method will always be null for a table level
//constraint but not for a column level constraint
uniqueSpecification
uniqueSpecification ::= <UNIQUE>
| <PRIMARY> <KEY>



uniqueColumnList
uniqueColumnList ::= columnNameList



referentialConstraintDefinition
referentialConstraintDefinition ::= <FOREIGN> <KEY> <LEFT_PAREN> columnNameList <RIGHT_PAREN> referencesSpecification



referencesSpecification
referencesSpecification ::= <REFERENCES> referencedTableAndColumns ( <ON> referentialTriggeredAction )?



referencedTableAndColumns
referencedTableAndColumns ::= qualifiedName ( <LEFT_PAREN> columnNameList <RIGHT_PAREN> )?



referentialTriggeredAction
referentialTriggeredAction ::= ( updateRule ( <ON> deleteRule )? | deleteRule ( <ON> updateRule )? )



updateRule
updateRule ::= <UPDATE> updateReferentialAction



deleteRule
deleteRule ::= <DELETE> deleteReferentialAction



updateReferentialAction
updateReferentialAction ::= <RESTRICT>
| <NO> <ACTION>



deleteReferentialAction
deleteReferentialAction ::= <CASCADE>
| <RESTRICT>
| <NO> <ACTION>
| <SET> ( <NULL> | <_DEFAULT> )

/*
 * constraintCharacteristics
 */
constraintCharacteristics
constraintCharacteristics ::= ( ( initiallyDeferred ) ( deferrable )? ( constraintEnforcement )? | ( deferrable ) ( initiallyDeferred )? ( constraintEnforcement )? | constraintEnforcement )

/*
 * initiallyDeferred
 */
initiallyDeferred
initiallyDeferred ::= <INITIALLY> ( <IMMEDIATE> | <DEFERRED> )

/*
 * deferrable
 */
deferrable
deferrable ::= ( <NOT> )? <DEFERRABLE>

/*
 * constraintEnforcement
 */
constraintEnforcement
constraintEnforcement ::= ( <NOT> )? <ENFORCED>

/*
 * columnConstraintDefinition
 */
columnConstraintDefinition
columnConstraintDefinition ::= ( constraintNameDefinition )? columnConstraint ( constraintCharacteristics )?

/*
 * columnConstraint
 */
columnConstraint
columnConstraint ::= <NOT> <NULL>
| uniqueSpecification ( propertyList <CHECK_PROPERTIES> )?
| referencesSpecification ( propertyList <CHECK_PROPERTIES> )?
| checkConstraintDefinition

/*
 * dropRoleStatement
 */
dropRoleStatement
dropRoleStatement ::= <ROLE> identifier



dropSchemaStatement
dropSchemaStatement ::= <SCHEMA> identifier <RESTRICT>



alterTableStatement
alterTableStatement ::= <TABLE> qualifiedName alterTableBody



alterTableBody
alterTableBody ::= <COMPRESS> ( inplaceCompress | sequentialCompress )
| <ALL> ( dropStatistics | updateStatistics )
| <UPDATE> <STATISTICS> ( identifier )
| <STATISTICS> <DROP> ( identifier )
| <DROP> ( dropColumnDefinition | dropTableConstraintDefinitionCore )
| alterTableAction

/*
 * Called for ALTER TABLE ALL DROP STATISTICS. This is an internal
 *  syntax and can't be invoked by a user directly. DERBY-4115. This
 *  will drop all the statistics for the given table name
 *
 * By the time we get here, we've parsed
 *    ALTER TABLE tablename ALL 
 * and here we parse DROP STATISTICS clause
 */
dropStatistics
dropStatistics ::= <DROP> <STATISTICS>

/*
 * Called for ALTER TABLE ALL UPDATE STATISTICS. This is an internal
 *  syntax and can't be invoked by a user directly. DERBY-269. This
 *  will update all the statistics for the given table name
 *
 * By the time we get here, we've parsed
 *    ALTER TABLE tablename ALL 
 * and here we parse UPDATE STATISTICS clause
 */
updateStatistics
updateStatistics ::= <UPDATE> <STATISTICS>



inplaceCompress
inplaceCompress ::= <INPLACE> ( ( <PURGE> )? ( <DEFRAGMENT> )? ( <TRUNCATE_END> )? )



sequentialCompress
sequentialCompress ::= ( <SEQUENTIAL> )?

/*
 * alterTableRenameTableStatement
 */
/*
StatementNode
alterTableRenameTableStatement(TableName tableName) throws StandardException :
{
	String newTableName;
}
{
	 newTableName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
	{
        return new RenameNode(
							null,
							newTableName,
                            true,
                            StatementType.RENAME_TABLE,
							getContextManager());
	}
}
*/

/*
 * alterTableRenameColumnStatement
 */
/*
StatementNode
alterTableRenameColumnStatement(TableName tableName) throws StandardException :
{
	String oldColumnName;
	String newColumnName;
}
{
	oldColumnName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)  newColumnName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
	{
        return new RenameNode(
							tableName,
							oldColumnName,
							newColumnName,
                            true,
                            StatementType.RENAME_COLUMN,
							getContextManager());
	}
}
*/
alterTableAction
alterTableAction ::= <ADD> ( addColumnDefinition | tableConstraintDefinition )
| <ALTER> ( <COLUMN> )? identifier columnAlterClause
| <ALTER> constraintNameDefinition constraintEnforcement
| DB2lockGranularityClause

/*
 * Handle
 *
 *    ALTER TABLE tablename DROP [ COLUMN ] columnname [ CASCADE | RESTRICT ]
 */
dropColumnDefinition
dropColumnDefinition ::= ( <COLUMN> )? identifier dropColumnReferentialAction



dropColumnReferentialAction
dropColumnReferentialAction ::= ( <CASCADE> | <RESTRICT> )?



addColumnDefinition
addColumnDefinition ::= ( <COLUMN> )? columnDefinition

/*
 * Various variants of the ALTER TABLE ALTER COLUMN statement.
 *
 * By the time we get here, we've parsed
 *    ALTER TABLE tablename ALTER [COLUMN] columnname
 * and here we parse the remainder of the ALTER COLUMN clause, one of:
 *		SET DATA TYPE data_type
 *		SET INCREMENT BY increment_value
 *		RESTART WITH increment_restart_value
 *		[SET | WITH] DEFAULT default_value
 *      DROP DEFAULT
 *      SET NOT NULL
 *      DROP NOT NULL
 *      [NOT] NULL
 */
columnAlterClause
columnAlterClause ::= <SET> <DATA> <TYPE> dataTypeDDL
| <RESTART> <WITH> exactNumber
| <SET> <GENERATED> alterGeneratedColumn
| <SET> columnAlterIdentityClause
| ( <SET> )? defaultClause
| <DROP> <_DEFAULT>
| ( <NULL> | <DROP> <NOT> <NULL> )
| ( <NOT> <NULL> | <SET> <NOT> <NULL> )

/*
 * Various variants of the ALTER TABLE ALTER COLUMN SET statement.
 *
 * By the time we get here, we've parsed
 *    ALTER TABLE tablename ALTER [COLUMN] columnname SET
 *		INCREMENT BY increment_value
 *      [NO] CYCLE
 */
columnAlterIdentityClause
columnAlterIdentityClause ::= <INCREMENT> <BY> exactNumber
| <CYCLE>
| <NO> <CYCLE>

/*
 * Various variants of the ALTER TABLE ALTER COLUMN SET GENERATED statement.
 *
 * By the time we get here, we've parsed
 *    ALTER TABLE ALTER COLUMN SET GENERATED
 */
alterGeneratedColumn
alterGeneratedColumn ::= <BY> <_DEFAULT>
| <ALWAYS>



dropTableConstraintDefinitionCore
dropTableConstraintDefinitionCore ::= dropTableConstraintDefinition



dropTableConstraintDefinition
dropTableConstraintDefinition ::= <CONSTRAINT> qualifiedName
| <PRIMARY> <KEY>
| <FOREIGN> <KEY> qualifiedName
| <UNIQUE> qualifiedName
| <CHECK> qualifiedName

/*
 * dropTableStatement
 */
dropTableStatement
dropTableStatement ::= <TABLE> qualifiedName

/*
 * dropIndexStatement
 */
dropIndexStatement
dropIndexStatement ::= <INDEX> qualifiedName

/*
 * dropAliasStatement
 */
dropAliasStatement
dropAliasStatement ::= <PROCEDURE> qualifiedName
| <FUNCTION> qualifiedName
| <SYNONYM> qualifiedName
| <TYPE> qualifiedName <RESTRICT>
| <DERBY> <AGGREGATE> qualifiedName <RESTRICT>



dropViewStatement
dropViewStatement ::= <VIEW> qualifiedName



dropTriggerStatement
dropTriggerStatement ::= <TRIGGER> qualifiedName



truncateTableStatement
truncateTableStatement ::= <TRUNCATE> <TABLE> qualifiedName

/*
 * grantStatement
 */
grantStatement
grantStatement ::= <GRANT> ( tableGrantStatement | routineGrantStatement | usageGrantStatement )
| <GRANT> ( roleGrantStatement )

/*
 * tableGrantStatement
 */
tableGrantStatement
tableGrantStatement ::= tablePrivileges <TO> granteeList

// end of tableGrantStatement

/*
 * tablePrivileges
 */
tablePrivileges
tablePrivileges ::= tableActions <ON> ( <TABLE> )? qualifiedName

// end of   tablePrivilege                               

/*
 * tableActions
 */
tableActions
tableActions ::= <ALL> <PRIVILEGES>
| tableAction ( <COMMA> tableAction )*

// end of tableActions

/*
 * routineGrantStatement
 */
routineGrantStatement
routineGrantStatement ::= <EXECUTE> <ON> routineDesignator <TO> granteeList

// end of routineGrantStatement

/*
 * usageGrantStatement
 */
usageGrantStatement
usageGrantStatement ::= <USAGE> <ON> usableObjects qualifiedName <TO> granteeList

// end of usageGrantStatement

/*
 * usableObjects
 */
usableObjects
usableObjects ::= <DERBY> <AGGREGATE>
| <SEQUENCE>
| <TYPE>

// end of routineGrantStatement

/*
 * routineAlias
 */
routineDesignator
routineDesignator ::= ( <FUNCTION> | <PROCEDURE> ) qualifiedName ( <LEFT_PAREN> parameterTypeList <RIGHT_PAREN> )?

// end of routineDesignator


/*
 * parameterTypeList
 */
parameterTypeList
parameterTypeList ::= ( catalogType ( <COMMA> catalogType )* )?

// end of parameterTypeList


/*
 * tableAction
 */
tableAction
tableAction ::= <SELECT> ( privilegeColumnList )?
| <DELETE>
| <INSERT>
| <UPDATE> ( privilegeColumnList )?
| <REFERENCES> ( privilegeColumnList )?
| <TRIGGER>

// end of tableAction

/*
 * privilegeColumnList
 */
privilegeColumnList
privilegeColumnList ::= <LEFT_PAREN> columnNameList <RIGHT_PAREN>

// end of privilegeColumnList

/*
 * granteeList
 */
granteeList
granteeList ::= grantee ( <COMMA> grantee )*



grantee
grantee ::= identifier
| <PUBLIC>

/*
 * roleGrantStatement
 */
roleGrantStatement
roleGrantStatement ::= roleList <TO> granteeList

/*
 * roleList
 */
roleList
roleList ::= roleElement ( <COMMA> roleElement )*

/*
 * roleElement
 */
roleElement
roleElement ::= identifier

/*
 * revokeStatement
 */
revokeStatement
revokeStatement ::= <REVOKE> ( tableRevokeStatement | routineRevokeStatement | usageRevokeStatement )
| <REVOKE> ( roleRevokeStatement )

/*
 * tableRevokeStatement
 */
tableRevokeStatement
tableRevokeStatement ::= tablePrivileges <FROM> granteeList

// end of tableRevokeStatement

/*
 * routineRevokeStatement
 */
routineRevokeStatement
routineRevokeStatement ::= <EXECUTE> <ON> routineDesignator <FROM> granteeList <RESTRICT>

// end of routineRevokeStatement

/*
 * usageRevokeStatement
 */
usageRevokeStatement
usageRevokeStatement ::= <USAGE> <ON> usableObjects qualifiedName <FROM> granteeList <RESTRICT>

// end of usageRevokeStatement


/*
 * roleRevokeStatement
 */
roleRevokeStatement
roleRevokeStatement ::= roleList <FROM> granteeList

/*
 * identifier
 */
internalIdentifier
internalIdentifier ::= <IDENTIFIER>
| delimitedIdentifier
| nonReservedKeyword



identifier
identifier ::= internalIdentifier

/*
 * delimitedIdentifier
 */
delimitedIdentifier
delimitedIdentifier ::= <DELIMITED_IDENTIFIER>

/*
 * reservedKeyword
 */
reservedKeyword
reservedKeyword ::= ( <ADD> | <ALL> | <ALLOCATE> | <ALTER> | <AND> | <ANY> | <ARE> | <AS> | <ASC> | <ASSERTION> | <AT> | <AUTHORIZATION> | <AVG> | <BEGIN> | <BETWEEN> | <BIT> | <BOTH> | <BY> | <CASCADE> | <CASCADED> | <CASE> | <CAST> | <CHAR> | <CHARACTER> | <CHECK> | <CLOSE> | <COLLATE> | <COLLATION> | <COLUMN> | <COMMIT> | <CONNECT> | <CONNECTION> | <CONSTRAINT> | <CONSTRAINTS> | <CONTINUE> | <CONVERT> | <CORRESPONDING> | <CREATE> | <CROSS> | <CURRENT> | <CURRENT_DATE> | <CURRENT_TIME> | <CURRENT_TIMESTAMP> | <CURRENT_USER> | <CURSOR> | <DEALLOCATE> | <DEC> | <DECIMAL> | <DECLARE> | <_DEFAULT> | <DEFERRABLE> | <DEFERRED> | <DELETE> | <DESC> | <DESCRIBE> | <DIAGNOSTICS> | <DISCONNECT> | <DISTINCT> | <DOUBLE> | <DROP> | <ELSE> | <END> | <ENDEXEC> | <ESCAPE> | <EXCEPT> | <EXCEPTION> | <EXEC> | <EXECUTE> | <EXISTS> | <EXTERNAL> | <FALSE> | <FETCH> | <FIRST> | <FLOAT> | <FOR> | <FOREIGN> | <FOUND> | <FROM> | <FULL> | <FUNCTION> | <GET> | <GET_CURRENT_CONNECTION> | <GLOBAL> | <GO> | <GOTO> | <GRANT> | <GROUP> | <HAVING> | <HOUR> | <IDENTITY> | <IMMEDIATE> | <IN> | <INDICATOR> | <INITIALLY> | <INNER> | <INOUT> | <INPUT> | <INSENSITIVE> | <INSERT> | <INT> | <INTEGER> | <INTERSECT> | <INTO> | <IS> | <ISOLATION> | <JOIN> | <KEY> | <LAST> | <LEADING> | <LEFT> | <LIKE> | <LOWER> | <MATCH> | <MAX> | <MIN> | <MINUTE> | <NATIONAL> | <NATURAL> | <NCHAR> | <NVARCHAR> | <NEXT> | <NO> | <NONE> | <NOT> | <NULL> | <NULLIF> | <NUMERIC> | <OF> | <ON> | <ONLY> | <OPEN> | <OPTION> | <OR> | <ORDER> | <OUT> | <OUTER> | <OUTPUT> | <OVERLAPS> | <PAD> | <PARTIAL> | <PREPARE> | <PRESERVE> | <PRIMARY> | <PRIOR> | <PRIVILEGES> | <PROCEDURE> | <PUBLIC> | <READ> | <REAL> | <REFERENCES> | <RELATIVE> | <RESTRICT> | <REVOKE> | <RIGHT> | <ROLLBACK> | <ROWS> | <SCHEMA> | <SCROLL> | <SECOND> | <SELECT> | <SESSION_USER> | <SET> | <SMALLINT> | <SOME> | <SPACE> | <SQL> | <SQLCODE> | <SQLERROR> | <SQLSTATE> | <SUBSTRING> | <SUM> | <SYSTEM_USER> | <TABLE> | <TEMPORARY> | <TIMEZONE_HOUR> | <TIMEZONE_MINUTE> | <TO> | <TRAILING> | <TRANSACTION> | <TRANSLATE> | <TRANSLATION> | <TRUE> | <UNION> | <UNIQUE> | <UNKNOWN> | <UPDATE> | <UPPER> | <USER> | <USING> | <VALUES> | <VARCHAR> | <VARYING> | <VIEW> | <WHENEVER> | <WHERE> | <WITH> | <WORK> | <WRITE> | <YEAR> | <BOOLEAN> | <CALL> | <CURRENT_ROLE> | <EXPLAIN> | <BIGINT> | <LTRIM> | <RTRIM> | <TRIM> | <SUBSTR> | <XML> | <XMLPARSE> | <XMLSERIALIZE> | <XMLEXISTS> | <XMLQUERY> )

/*
 * nonReservedKeyword
 */
nonReservedKeyword
nonReservedKeyword ::= ( <ABS> | <ABSVAL> | <ACTION> | <AFTER> | <AGGREGATE> | <ALWAYS> | <BEFORE> | <BINARY> | <BLOB> | <C> | <CALLED> | <CLASS> | <CLOB> | <COALESCE> | <COBOL> | <COMMITTED> | <COMPRESS> | <CONCAT> | <CONTAINS> | <CONTENT> | <COUNT> | <CS> | <CURDATE> | <CURTIME> | <CYCLE> | <D> | <DATA> | <DATE> | <DAY> | <DEFRAGMENT> | <DIRTY> | <DYNAMIC> | <DATABASE> | <DB2SQL> | <DERBY> | <DERBY_JDBC_RESULT_SET> | <DOCUMENT> | <ENFORCED> | <EACH> | <EMPTY> | <EXCLUSIVE> | <FN> | <FORTRAN> | <GENERATED> | <IDENTITY_VAL_LOCAL> | <INCREMENT> | <INDEX> | <INITIAL> | <INPLACE> | <INTERVAL> | <JAVA> | <LANGUAGE> | <LARGE> | <LCASE> | <LENGTH> | <LEVEL> | <LIMIT> | <LOCATE> | <LOCK> | <LOCKS> | <LOCKSIZE> | <LOGGED> | <LONG> | <MATCHED> | <MAXVALUE> | <MERGE> | <MINVALUE> | <MESSAGE_LOCALE> | <METHOD> | <MOD> | <MODE> | <MODIFIES> | <MODIFY> | <MODULE> | <MONTH> | <_MORE> | <MUMPS> | <NAME> | <NCLOB> | <NEW> | <NEW_TABLE> | <NULLABLE> | <NULLS> | <NUMBER> | <OBJECT> | <OFF> | <OFFSET> | <OLD> | <OLD_TABLE> | <OJ> | <OVER> | <PASCAL> | <PASSING> | <PLI> | <PRECISION> | <PROPERTIES> | <PURGE> | <READS> | <REF> | <RELEASE> | <RENAME> | <REPEATABLE> | <REFERENCING> | <RESET> | <RESTART> | <RESULT> | <RETAIN> | <RETURNING> | <RETURNS> | <ROLE> | <ROLLUP> | <ROW> | <ROWNUMBER> | <RR> | <RS> | <SCALE> | <SAVEPOINT> | <SECURITY> | <SEQUENCE> | <SEQUENTIAL> | <SERIALIZABLE> | <SETS> | <SHARE> | <SPECIFIC> | <SQLID> | <SQL_TSI_FRAC_SECOND> | <SQL_TSI_SECOND> | <SQL_TSI_MINUTE> | <SQL_TSI_HOUR> | <SQL_TSI_DAY> | <SQL_TSI_WEEK> | <SQL_TSI_MONTH> | <SQL_TSI_QUARTER> | <SQL_TSI_YEAR> | <SQRT> | <STABILITY> | <START> | <STATEMENT> | <STATISTICS> | <STRIP> | <SYNONYM> | <STYLE> | <T> | <THEN> | <TIME> | <TIMESTAMP> | <TIMESTAMPADD> | <TIMESTAMPDIFF> | <TRIGGER> | <TRUNCATE> | <TRUNCATE_END> | <TS> | <TYPE> | <UCASE> | <UNCOMMITTED> | <UR> | <USAGE> | <VALUE> | <VARBINARY> | <PARAMETER> | <WHEN> | <WHITESPACE> )

/*
 * caseSensitiveIdentifierPlusReservedWords
 */
caseSensitiveIdentifierPlusReservedWords
caseSensitiveIdentifierPlusReservedWords ::= caseSensitiveIdentifier
| reservedKeyword

/*
 * caseInsensitiveIdentifierPlusReservedWords
 */
caseInsensitiveIdentifierPlusReservedWords
caseInsensitiveIdentifierPlusReservedWords ::= identifier
| reservedKeyword

/*
 * caseSensitiveIdentifier
 */
caseSensitiveIdentifier
caseSensitiveIdentifier ::= <IDENTIFIER>
| delimitedIdentifier
| nonReservedKeyword