Thread: function param problem in 7.3

function param problem in 7.3

From
"frank_lupo"
Date:
I have create a function in 7.2:

CREATE FUNCTION left(text,int2) RETURNS varchar AS '
DECLARE
        BEGIN
            RETURN substring($1,1,$2)::varchar;
        END;'
language 'plpgsql';

I execute a function in 7.2:

test=# select left('pippo',2)\g
 left
------
 pi
(1 row)


I execute a function in 7.3:

test=# select left('pippo',2)\g
ERROR:  Function left("unknown", integer) does not exist
        Unable to identify a function that satisfies the given argument types
        You may need to add explicit typecasts

test=# select left('pippo'::text,2::int2)\g
 left
------
 pi
(1 row)

why in 7.2 this function worked while in 7.3 it does not work?

Thanks


Bye !!
Frank Lupo (Wolf) !!

       /\_ _/\
       \ o o /
--ooo-----ooo---





--
Prendi GRATIS l'email universale che... risparmia: http://www.email.it/f

Sponsor:
Interessi alti con Conto Arancio. Facile come cliccare qui.
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=661&d=10-3

Re: function param problem in 7.3

From
Tom Lane
Date:
"=?iso-8859-1?Q?frank=5Flupo?=" <frank_lupo@email.it> writes:
> I have create a function in 7.2:
>
> CREATE FUNCTION left(text,int2) RETURNS varchar AS '

> I execute a function in 7.3:
>
> test=# select left('pippo',2)\g
> ERROR:  Function left("unknown", integer) does not exist

int4-to-int2 conversion is not implicit in 7.3.  You'd be better off to
declare the function as taking int --- declaring it as int2 was a useless
anti-optimization even in 7.2, seeing that substring() takes int not
int2.

            regards, tom lane