Thread: Function Issue and casting

Function Issue and casting

From
Juan Pablo Cook
Date:
Hi friends, It's my first time I'm writing to the list. All days I enjoy the list!
I declare a function, and when I want to call this, it fails.

My function:
CREATE OR REPLACE FUNCTION alta_docente(integer,varchar,varchar,varchar,bigint,varchar,integer)
RETURNS VOID AS
$body$
declare
    codigo integer;
begin
    INSERT INTO persona(cod,dni,nombre,apellido,domicilio,telefono) VALUES (DEFAULT,$1,$2,$3,$4,$5);
    codigo := currval('persona_cod_seq');

        INSERT INTO persona_docente(cod,legajo,antiguedad) VALUES (codigo,$6,$7);
end;
$body$
LANGUAGE 'plpgsql';

The call I'm doing:
SELECT alta_docente(2323232,cast('Mariela' AS varchar),cast('Botti' AS varchar),cast('232 de Noviemb23' AS varchar),cast(2312312321AS bigint),cast('323232A' AS varchar),23)

And here is the error:

ERROR:  function alta_docente(integer, character varying, character varying, character varying, bigint, character varying, integer) does not exist at character 8
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
STATEMENT:  SELECT alta_docente(2323232,cast('Mariela' AS varchar),cast('Botti' AS varchar),cast('232 de Noviemb23' AS varchar),cast(2312312321AS bigint),cast('323232A' AS varchar),23)

I don't know what's the problem, because I did all the explicit cast I think to convert types. If someone can help me, It would be great!

Thanks a lot

JP Cook

Sorry about my bad english!

Re: Function Issue and casting

From
Adrian Klaver
Date:
On Saturday 04 July 2009 10:47:34 am Juan Pablo Cook wrote:
> Hi friends, It's my first time I'm writing to the list. All days I enjoy
> the list!
> I declare a function, and when I want to call this, it fails.
>
> My function:
> CREATE OR REPLACE FUNCTION
> alta_docente(integer,varchar,varchar,varchar,bigint,varchar,integer)
> RETURNS VOID AS
> $body$
> declare
>     codigo integer;
> begin
>     INSERT INTO persona(cod,dni,nombre,apellido,domicilio,telefono) VALUES
> (DEFAULT,$1,$2,$3,$4,$5);
>     codigo := currval('persona_cod_seq');
>
>         INSERT INTO persona_docente(cod,legajo,antiguedad) VALUES
> (codigo,$6,$7);
> end;
> $body$
> LANGUAGE 'plpgsql';
>
> The call I'm doing:
> SELECT alta_docente(2323232,cast('Mariela' AS varchar),cast('Botti' AS
> varchar),cast('232 de Noviemb23' AS varchar),cast(2312312321AS
> bigint),cast('323232A' AS varchar),23)
>
> And here is the error:
>
> ERROR:  function alta_docente(integer, character varying, character
> varying, character varying, bigint, character varying, integer) does not
> exist at character 8
> HINT:  No function matches the given name and argument types. You might
> need to add explicit type casts.
> STATEMENT:  SELECT alta_docente(2323232,cast('Mariela' AS
> varchar),cast('Botti' AS varchar),cast('232 de Noviemb23' AS
> varchar),cast(2312312321AS bigint),cast('323232A' AS varchar),23)
>
> I don't know what's the problem, because I did all the explicit cast I
> think to convert types. If someone can help me, It would be great!
>
> Thanks a lot
>
> JP Cook
>
> Sorry about my bad english!

Is this a schema path issue? Did you create function in one schema and call it
from another which does not have access to the function schema? Two things to
check are the search path and whether the user calling the function has rights
to the schema containing the function.

--
Adrian Klaver
aklaver@comcast.net

Function Issue and casting

From
Juan Pablo Cook
Date:
Adrian, thanks a lot!!! for your quicky reply. Thats the error!, my casting was ok, but my schema path was wrong. I didn't realize that.
Thanks a lot!

Bye!


On Sat, Jul 4, 2009 at 3:25 PM, Adrian Klaver <aklaver@comcast.net> wrote:
On Saturday 04 July 2009 10:47:34 am Juan Pablo Cook wrote:
> Hi friends, It's my first time I'm writing to the list. All days I enjoy
> the list!
> I declare a function, and when I want to call this, it fails.
>
> My function:
> CREATE OR REPLACE FUNCTION
> alta_docente(integer,varchar,varchar,varchar,bigint,varchar,integer)
> RETURNS VOID AS
> $body$
> declare
>     codigo integer;
> begin
>     INSERT INTO persona(cod,dni,nombre,apellido,domicilio,telefono) VALUES
> (DEFAULT,$1,$2,$3,$4,$5);
>     codigo := currval('persona_cod_seq');
>
>         INSERT INTO persona_docente(cod,legajo,antiguedad) VALUES
> (codigo,$6,$7);
> end;
> $body$
> LANGUAGE 'plpgsql';
>
> The call I'm doing:
> SELECT alta_docente(2323232,cast('Mariela' AS varchar),cast('Botti' AS
> varchar),cast('232 de Noviemb23' AS varchar),cast(2312312321AS
> bigint),cast('323232A' AS varchar),23)
>
> And here is the error:
>
> ERROR:  function alta_docente(integer, character varying, character
> varying, character varying, bigint, character varying, integer) does not
> exist at character 8
> HINT:  No function matches the given name and argument types. You might
> need to add explicit type casts.
> STATEMENT:  SELECT alta_docente(2323232,cast('Mariela' AS
> varchar),cast('Botti' AS varchar),cast('232 de Noviemb23' AS
> varchar),cast(2312312321AS bigint),cast('323232A' AS varchar),23)
>
> I don't know what's the problem, because I did all the explicit cast I
> think to convert types. If someone can help me, It would be great!
>
> Thanks a lot
>
> JP Cook
>
> Sorry about my bad english!

Is this a schema path issue? Did you create function in one schema and call it
from another which does not have access to the function schema? Two things to
check are the search path and whether the user calling the function has rights
to the schema containing the function.

--
Adrian Klaver
aklaver@comcast.net