How to get scalar value of "floatlike" decimal?
Hello Developers-list, I am writing some C function (something like "cast"), and I have problem with proper handling of value type "any". Say, I have C function: str testFn(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { str* ret = getArgReference_str(stk, pci, 0); ValPtr sourceValue = &stk->stk[pci->argv[1]]; char tmp[256] = {0}; sprintf(&tmp[0], "Source value type is \"%s\" (%d)\n", getTypeName(sourceValue->vtype), sourceValue->vtype); *ret = GDKstrdup(&tmp[0}); return MAL_SUCCEED; } MAL function: pattern testFn(value:any_1):str address testFn comment "Test function"; Then I added follow code to sql_types.c, where all built-in types and functions gets initialized: sql_create_func(sa, "testFn", "somemodule", "testFn", ANY, NULL, STR, SCALE_NONE); When I want to pass "float" number, I get only integer, for example: SELECT testFn(123.12); I will get "int" type of ValRecord. And value of passed argument will be "12312" (without dot-delimiter). But, I expecting double or float value. Please, help to solve this. -- Best regards, Sherzod mailto:shmutalov@gmail.com
Hi, apparently, our SQL parser reconizes literal 123.12 as (fixed-point) decimal (which is stored using int) rather than as floating point. Try (all of) SELECT testFn(cast(123.12 as real)); SELECT testFn(cast(123.12 as float)); SELECT testFn(cast(123.12 as double)); Best, Stefan ----- On Aug 19, 2015, at 8:38 AM, Sherzod Mutalov shmutalov@gmail.com wrote:
Hello Developers-list,
I am writing some C function (something like "cast"), and I have problem with proper handling of value type "any".
Say, I have C function:
str testFn(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { str* ret = getArgReference_str(stk, pci, 0); ValPtr sourceValue = &stk->stk[pci->argv[1]];
char tmp[256] = {0};
sprintf(&tmp[0], "Source value type is \"%s\" (%d)\n", getTypeName(sourceValue->vtype), sourceValue->vtype);
*ret = GDKstrdup(&tmp[0});
return MAL_SUCCEED; }
MAL function:
pattern testFn(value:any_1):str address testFn comment "Test function";
Then I added follow code to sql_types.c, where all built-in types and functions gets initialized:
sql_create_func(sa, "testFn", "somemodule", "testFn", ANY, NULL, STR, SCALE_NONE);
When I want to pass "float" number, I get only integer, for example:
SELECT testFn(123.12);
I will get "int" type of ValRecord. And value of passed argument will be "12312" (without dot-delimiter). But, I expecting double or float value.
Please, help to solve this. -- Best regards, Sherzod mailto:shmutalov@gmail.com
_______________________________________________ developers-list mailing list developers-list@monetdb.org https://www.monetdb.org/mailman/listinfo/developers-list
-- | Stefan.Manegold@CWI.nl | DB Architectures (DA) | | www.CWI.nl/~manegold/ | Science Park 123 (L321) | | +31 (0)20 592-4212 | 1098 XG Amsterdam (NL) |
participants (2)
-
Sherzod Mutalov
-
Stefan Manegold