Attaching derby-4513_01-aa-illegalContexts.diff. This patch prevents you from using a NEXT VALUE FOR clause in the following situations:
o WHERE/HAVING/ON clauses
o Aggregates and GROUP BY expressions
o DISTINCT and ORDER BY expressions
o CASE expressions
o CHECK constraints and generation clauses
The limitations imposed by this patch are more restrictive than what the SQL Standard allows:
o Only one NEXT VALUE FOR expression is allowed per sequence per statement.
o NEXT VALUE FOR is not allowed in any statement which has a DISTINCT or ORDER BY expression.
When these limitations are checked in, I will create another JIRA to track the fact that Derby is more restrictive than the Standard allows. We can consider relaxing limitations which users find onerous.
Touches the following files
The compiler context now tracks which sequences are mentioned in the statement.
Statements which have DISTINCT and ORDER BY expressions are marked so that the bind() logic can reject NEXT VALUE FOR clauses.
Bind() logic to reject NEXT VALUE FOR in illegal situations.
New error messages.