implicite datacasting

View: New views
2 Messages — Rating Filter:   Alert me  

implicite datacasting

by Hardie82 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have a problem with an insert-statement. I have an application that used a hsqldb. Now I want to switch to derby but got the problem that derby didn't cast an integer to a char-column. I always get an exception by the following example:

INSERT INTO table1 (id, name, code) VALUES (1, 'somebody', 03184)

Column code is type varchar(20) and I read elcewhere that derby implicite could parse this to varchar. Is this correct or should I cast it manually like

INSERT INTO table1 (id, name, code) VALUES (1, 'somebody', '03184') ?

By the way with hsqldb the error didn't occur.

Greetings

Re: implicite datacasting

by Rick Hillegas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

This is a known issue with Derby, tracked by
https://issues.apache.org/jira/browse/DERBY-3662

In addition to the workaround you mentioned, you can write your own
casting function.  Your statement would look something like this:

   INSERT INTO table1 (id, name, code) VALUES (1, 'somebody',
myCastingFunction( 03184) )

Hope this helps,
-Rick


Hardie82 wrote:

> Hi,
>
> I have a problem with an insert-statement. I have an application that used a
> hsqldb. Now I want to switch to derby but got the problem that derby didn't
> cast an integer to a char-column. I always get an exception by the following
> example:
>
> INSERT INTO table1 (id, name, code) VALUES (1, 'somebody', 03184)
>
> Column code is type varchar(20) and I read elcewhere that derby implicite
> could parse this to varchar. Is this correct or should I cast it manually
> like
>
> INSERT INTO table1 (id, name, code) VALUES (1, 'somebody', '03184') ?
>
> By the way with hsqldb the error didn't occur.
>
> Greetings
>