db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dag H. Wanvik (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-4426) With generated columns, INSERT with DEFAULT inside a VALUES clause inside a UNION fails.
Date Tue, 27 Oct 2009 17:36:59 GMT

    [ https://issues.apache.org/jira/browse/DERBY-4426?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770589#action_12770589

Dag H. Wanvik commented on DERBY-4426:

This is related to DERBY-4413, it's just that in this case the sorting
happens as a part of evaluating a UNION, and this time, the empty
"stub" column of the generated column (to be filled in later), *is*
part of the sort key.

I have revisited the standard here, and it seems DEFAULT is actually
not allowed inside the UNION here: The production that allows DEFAULT
as part of its derivation is the <contextually typed table
constructor> (SQL 2003, section 7.3), which is only used in a
production here:

<insert statement> ::=
   INSERT INTO <insertion target> <insert columns and source>
   <insertion target> ::= <table name>
   <insert columns and source> ::=
   <from subquery>
   | <from constructor>
   | <from default>

<from constructor> ::=
   [ <left paren> <insert column list> <right paren> ]
   [ <override clause> ]
   <contextually typed table value constructor>

If a UNION is present, it is derivable only via the <from subquery>,
which in turn leads to a "normal" <table value constructor>,
cf. section 7.13 <query expression>:

<simple table> ::=
   <query specification>
   | <table value constructor>
   | <explicit table>

and I can't see that DEFAULT is allowed as part of a  <table value
constructor>. This seems reasonable, because the default values should
logically be applied only after the result set has been computed, cf
arguments for this in DERBY-4413.

If the column behind the DEFAULT is an identity column or a normal
base column, the query succeeds, so I would say we are too liberal
here. It only works because in those two cases, the values are
assigned "early" in the sense of DERBY-4413.

Tagging this issue with "Deviation from standard".

> With generated columns,  INSERT with DEFAULT inside a VALUES clause inside a UNION fails.
> -----------------------------------------------------------------------------------------
>                 Key: DERBY-4426
>                 URL: https://issues.apache.org/jira/browse/DERBY-4426
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions:,,
>            Reporter: Dag H. Wanvik
>            Priority: Minor
> Repro on trunk:
>  create table mytab (i int generated always as (j*2), j int);
> insert into tt values (default,1) union values (default,2);
> ERROR XJ001: Java exception: 'ASSERT FAILED col[0] is null: org.apache.derby.shared.common.sanity.AssertFailure'.
> java.sql.SQLException: Java exception: 'ASSERT FAILED col[0] is null: org.apache.derby.shared.common.sanity.AssertFailure'.
> 	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:95)
> 	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:142)
> 	at org.apache.derby.impl.jdbc.Util.javaException(Util.java:299)
> 	at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:403)
> 	at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:346)
> 	at org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2204)
> 	at org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:81)
> 	at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1323)
> 	at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:625)
> 	at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:555)
> 	at org.apache.derby.impl.tools.ij.ij.executeImmediate(ij.java:329)
> 	at org.apache.derby.impl.tools.ij.utilMain.doCatch(utilMain.java:521)
> 	at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(utilMain.java:363)
> 	at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:261)
> 	at org.apache.derby.impl.tools.ij.Main.go(Main.java:229)
> 	at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:184)
> 	at org.apache.derby.impl.tools.ij.Main.main(Main.java:75)
> 	at org.apache.derby.tools.ij.main(ij.java:59)
> Caused by: java.sql.SQLException: Java exception: 'ASSERT FAILED col[0] is null: org.apache.derby.shared.common.sanity.AssertFailure'.
> 	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:45)
> 	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory40.java:119)
> 	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:70)
> 	... 17 more
> Caused by: org.apache.derby.shared.common.sanity.AssertFailure: ASSERT FAILED col[0]
is null
> 	at org.apache.derby.shared.common.sanity.SanityManager.THROWASSERT(SanityManager.java:162)
> 	at org.apache.derby.shared.common.sanity.SanityManager.THROWASSERT(SanityManager.java:147)
> 	at org.apache.derby.impl.store.access.sort.MergeSort.checkColumnTypes(MergeSort.java:474)
> 	at org.apache.derby.impl.store.access.sort.MergeInserter.insert(MergeInserter.java:98)
> 	at org.apache.derby.impl.sql.execute.SortResultSet.loadSorter(SortResultSet.java:326)
> 	at org.apache.derby.impl.sql.execute.SortResultSet.openCore(SortResultSet.java:270)
> 	at org.apache.derby.impl.sql.execute.InsertResultSet.open(InsertResultSet.java:415)
> 	at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:436)
> 	at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:317)
> 	at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1235)

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message