Re: callproc type casts

Daniele Varrazzo <[email protected]> Tue, 10 Aug 2010 18:26:42 +0100
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Tue, Aug 10, 2010 at 5:52 PM, Imre Horvath <[email protected]> wrote:
> I've got a plpython function, with a character varying param.
> I can call it from sql.
>
> But when i try to call it with psycopg2.callproc('testfunc', ['test']),
> i've got the error:
> function testfunc(unknown) does not exist
> HINT: =A0No function matches the given name and argument types. You might
> need to add explicit type casts.

This works instead:

    In [13]: cur.callproc("upper", ['foo'])
    Out[13]: ['foo']

    In [14]: cur.fetchone()
    Out[14]: ('FOO',)

So, in what "testfunc" is different from Postgres' "upper"? I can see
that "upper" takes a text and returns a text:

    # select proargtypes, prorettype from pg_proc where proname =3D 'upper';
     proargtypes | prorettype
    -------------+------------
     25          |         25
    (1 row)

    # select typname from pg_type where oid =3D 25;
     typname
    ---------
     text
    (1 row)

What about yours? Do you have overloading functions? And, is the
namespace correct?

Does the function work wrapped in a query?

    cur.execute("select * from testfunc(%s)", ('test',))

Does it work specifying a varchar cast?

    cur.execute("select * from testfunc(%s::varchar)", ('test',))


-- Daniele