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

Rick Hillegas commented on DERBY-6479:
--------------------------------------

A common workaround for casting problems is to write your own casting function. 
Like so:

import java.sql.Blob;

import org.apache.derby.iapi.types.HarmonySerialBlob;

public class zz
{
    public  static  Blob  castToBlob( byte[] bytes ) throws Exception
    {
        return new HarmonySerialBlob( bytes );
    }
}

...and then use it like this:

connect 'jdbc:derby:memory:db;create=true';

create table blobTable( a blob );
create table binaryTable( a varchar( 16 ) for bit data );

-- works

insert into binaryTable select cast( a as varchar( 16 ) for bit data ) from 
blobTable;

-- fails
insert into blobTable select cast( a as blob ) from binaryTable;


create function castToBlob( bytes varchar( 16 ) for bit data ) returns blob
language java parameter style java no sql
external name 'zz.castToBlob';

-- works
insert into blobTable select castToBlob( a ) from binaryTable;


> Allow cast of BLOB to other binary types
> ----------------------------------------
>
>                 Key: DERBY-6479
>                 URL: https://issues.apache.org/jira/browse/DERBY-6479
>             Project: Derby
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 10.11.0.0
>            Reporter: Rick Hillegas
>
> The SQL Standard allows explicit casts between all binary types. See the 2011 
> edition of the Standard, part 6.13 (cast specification), syntax rule 6. 
> However, Derby doesnt' allow casts of BLOB to other binary types. We should 
> allow this. The following script shows the current behavior:
> connect 'jdbc:derby:memory:db;create=true';
> create table blobTable( a blob );
> create table binaryTable( a varchar( 16 ) for bit data );
> -- works
> insert into binaryTable select cast( a as varchar( 16 ) for bit data ) from 
> blobTable;
> -- fails
> insert into blobTable select cast( a as blob ) from binaryTable;



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to