db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephan van Loendersloot (LIST)" <step...@republika.nl>
Subject Re: Problem with cast
Date Tue, 04 Mar 2008 22:49:38 GMT


Thomas Kellerer wrote:
> Kathey Marsden wrote on 04.03.2008 22:57:
>> Thomas Kellerer wrote:
>>> When I run the following statement:
>>>
>>> SELECT cast(id AS VARCHAR) FROM mytable;
>>>
>>> I get an error:
>>>
>>> ERROR 42X01: Syntax error: Encountered ")" at line 1, column 26.
>>>
>> If you specified the length of the varchar, you would get a clearer 
>> message.
>> ij> select cast(id as VARCHAR(30)) from mytable;
>> ERROR 42846: Cannot convert types 'INTEGER' to 'VARCHAR'.
>>
>>
>> Perhaps doing
>> select id from mytable;
>>
>> and then using ResultSet.getString() to do the string conversion 
>> would work for you.
>>
>> Kathey
>>
>>
> So I cannot cast an integer to a varchar.
>
> I thought I'd seen a 'Y' in the relevant cell of the matrix describing 
> the allowed conversions in the manual. But a second look clearly shows 
> a -
>
> Thanks for the quick answer.
>
> Thomas
>
A workaround like the following might be of help:

SELECT TRIM(CAST(CAST(id AS CHAR(30)) AS VARCHAR(30))) FROM mytable;



Regards,

    --Stephan.

Mime
View raw message