You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Bryan Pendleton (JIRA)" <ji...@apache.org> on 2007/02/24 22:32:05 UTC

[jira] Commented: (DERBY-2371) Setting a default value for a VARCHAR column fails when column contains data

    [ https://issues.apache.org/jira/browse/DERBY-2371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12475654 ] 

Bryan Pendleton commented on DERBY-2371:
----------------------------------------

The problem arises in AlterTableConstantAction.modifyColumnDefault, which 
only understands two types of modifications that can be made to a column's default value:
 - changing the INCREMENT BY value for a generated IDENTITY column
 - changing the RESTART WITH value for a generated IDENTITY column

But there is a third type of modification that can be made to a column's default
value, which is simply to change the default value that is to be used for an
ordinary column if no value is provided when inserting a new row into that table.

The fix is to add a new ColumnInfo modification type code:
   MODIFY_COLUMN_DEFAULT_VALUE
and to teach ModifyColumnNode and AlterTableConstantAction what to do
for modifications of type MODIFY_COLUMN_DEFAULT_VALUE.

I've got a diff ready, and will post it after running the regression tests.


> Setting a default value for a VARCHAR column fails when column contains data
> ----------------------------------------------------------------------------
>
>                 Key: DERBY-2371
>                 URL: https://issues.apache.org/jira/browse/DERBY-2371
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.2.1.6, 10.2.2.0
>         Environment: This probably affects all platforms.
>            Reporter: Tim Dudgeon
>         Assigned To: Bryan Pendleton
>
> I'm seeing a problem updating the default value for a VARCHAR column when the column already contains data. I'm, using:
> alter table TABLE_NAME alter column COL_NAME DEFAULT 'new value'
> and with some VARCHAR columns I get an error like this:
> Invalid character string format for type long.; nested exception is java.sql.SQLException: Invalid character string format for type long.
> Caused by: ERROR 22018: Invalid character string format for type long.
>        at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
>        at org.apache.derby.iapi.types.SQLChar.getLong(Unknown Source)
>        at org.apache.derby.impl.sql.execute.AlterTableConstantAction.getColumnMax(Unknown Source)
>        at org.apache.derby.impl.sql.execute.AlterTableConstantAction.modifyColumnDefault(Unknown Source)
>        at org.apache.derby.impl.sql.execute.AlterTableConstantAction.execGuts(Unknown Source)
>        at org.apache.derby.impl.sql.execute.AlterTableConstantAction.executeConstantAction(Unknown Source)
>        at org.apache.derby.impl.sql.execute.MiscResultSet.open(Unknown Source)
>        at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
>        at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
>        at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>        at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
> This only happens on VARCHAR columns containing data. Columns that are entirely NULL update fine. 
> This was discussed on users mailing list:
> http://www.nabble.com/problem-with-ALTER-COLUMN-DEFAULT-on-VARCHAR-column-tf3274046.html
> and the conclusion was that it is related to this statement being run internally as part of the updata process:
> SELECT MAX(COL_NAME) FROM TABLE_NAME  
> As reported in that discussion:
> -bash-2.05b$ java org.apache.derby.tools.ij
> ij version 10.3
> ij> connect 'jdbc:derby:brydb';
> ij> create table t (a varchar(10));
> 0 rows inserted/updated/deleted
> ij> alter table t alter column a default 'my val';
> 0 rows inserted/updated/deleted
> ij> insert into t (a) values ('hi');
> 1 row inserted/updated/deleted
> ij> alter table t alter column a default 'another val';
> ERROR 22018: Invalid character string format for type long.

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