Hi, <nikhil.sonta...@enterprisedb.com> wrote:
> The following plpgsql function errors out with cvs head: > > CREATE function test_assign() returns void > AS > $$ declare x int; > BEGIN > x := 9E3/2; > END > $$ LANGUAGE 'plpgsql'; > > postgres=# select test_assign(); > ERROR: invalid input syntax for integer: "4500.0000000000000000" > CONTEXT: PL/pgSQL function "test_assign" line 3 at assignment > > We do have an existing cast from numeric to type integer. But here > basically we convert the value to string in exec_cast_value before calling > int4in. And then use of strtol in pg_atoi leads to this complaint. Guess > converting the value to string is not always a good strategy. > PFA, patch which uses find_coercion_pathway to find a direct COERCION_PATH_FUNC function and uses that if it is available. Or is there a better approach? Seems to handle the above issue with this patch. Regards, Nikhils -- http://www.enterprisedb.com
Index: src/pl/plpgsql/src/pl_exec.c =================================================================== RCS file: /repositories/postgreshome/cvs/pgsql/src/pl/plpgsql/src/pl_exec.c,v retrieving revision 1.225 diff -c -r1.225 pl_exec.c *** src/pl/plpgsql/src/pl_exec.c 20 Nov 2008 15:36:22 -0000 1.225 --- src/pl/plpgsql/src/pl_exec.c 29 Dec 2008 15:23:49 -0000 *************** *** 24,29 **** --- 24,30 ---- #include "funcapi.h" #include "nodes/nodeFuncs.h" #include "parser/scansup.h" + #include "parser/parse_coerce.h" #include "tcop/tcopprot.h" #include "utils/array.h" #include "utils/builtins.h" *************** *** 4732,4750 **** { if (!isnull) { ! char *extval; ! extval = convert_value_to_string(value, valtype); ! /* Allow input function to use SPI ... see notes above */ ! SPI_push(); ! value = InputFunctionCall(reqinput, extval, ! reqtypioparam, reqtypmod); ! SPI_pop(); ! pfree(extval); } else { --- 4733,4777 ---- { if (!isnull) { ! /* ! * find out if there is a coercion pathway via a function ! */ ! CoercionPathType pathtype; ! Oid castfunc; ! pathtype = find_coercion_pathway(reqtype, valtype, ! COERCION_ASSIGNMENT, ! &castfunc); ! ! if (pathtype == COERCION_PATH_FUNC) ! { ! FmgrInfo cast_func_finfo; ! ! fmgr_info_cxt(castfunc, &cast_func_finfo, ! CurrentMemoryContext); ! cast_func_finfo.fn_oid = InvalidOid; ! ! /* do we need reqtypmod for cast functions? */ ! value = FunctionCall2(&cast_func_finfo, ! value, ! reqtypmod); ! } ! else ! { ! char *extval; ! extval = convert_value_to_string(value, valtype); ! /* Allow input function to use SPI ... see notes above */ ! SPI_push(); ! value = InputFunctionCall(reqinput, extval, ! reqtypioparam, reqtypmod); ! SPI_pop(); ! ! pfree(extval); ! } } else {
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers