cast and overflow behaviour (number to char)

Posted by Admin on 23-Dec-2007 09:32

Does anyone have a document or bug reference with respect to how progress is managing a cast of a numeric which is too large for the target character field.

It would appear that Progress does not throw an exception but prefers to return asterisks which is not per the standard. It would appear that cast wants to add a trailing space which is also incorrect.

For example, this should return 10.23 as a char type but does not as it overflows as "**** "

select distinct cast ( cast ( 10.23 as decimal (4,2)) as char(5)) from sometable

Meanwhile this works as it allows for the unexpected trailing space

select distinct cast ( cast ( 10.23 as decimal (4,2)) as char(6)) from PRODUCT

All Replies

Posted by Thomas Mercer-Hursh on 23-Dec-2007 12:18

What do you expect when you don't give it enough space?

Posted by Admin on 02-Jan-2008 11:32

an overflow exception should be thrown.

Posted by Thomas Mercer-Hursh on 02-Jan-2008 12:04

And, why would you expect that in a language that has yet to acquire exceptions?

And, given that you would have to code to handle the exception gracefully, the code required to handle this without exceptions is really quite simple.

E.g., try out something like this.

DEFINE VARIABLE X AS CHARACTER.

ASSIGN X = STRING(99999,"9999") NO-ERROR.

DISPLAY X ERROR-STATUS:ERROR ERROR-STATUS:NUM-MESSAGES

SKIP ERROR-STATUS:get-message(1) FORMAT "X(60)".

Posted by Admin on 03-Jan-2008 15:06

I'm referring to what the SQL standard requires.

Consider a case where an exception is thrown

select cast ( systime() as char(2))
from "GOSALES1"."GOSALES1"."ORDERHEADER" "ORDERHEADER"


SQLFetch returned: SQL_ERROR=-1
: szSqlState = "HY000", *pfNativeError = -20152, *pcbErrorMsg = 102
szErrorMsg = "[DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Character string is too long (8184)"

Consider the case where it is not and further where the target field is in fact large enough if Progress were not trying to add a blank on the end.

select distinct cast ( cast ( 10.2 as decimal(3,2)) as char(4))
from "GOSALES1"."GOSALES1"."ORDERHEADER" "ORDERHEADER"

"convert(character(4,0),convert(numeric(3,2),10.200000))"
"*** "
1 row fetched from 1 column.

select distinct cast ( cast ( 10.2 as decimal(3,2)) as char(5))
from "GOSALES1"."GOSALES1"."ORDERHEADER" "ORDERHEADER"

Get Data All:
"convert(character(5,0),convert(numeric(3,2),10.200000))"
"10.2 "
1 row fetched from 1 column.

This thread is closed