Re: composite types
On Sun, Aug 29, 2010 at 2:35 PM, Imre Horvath <blemidon@...> wrote:
> How can I use composite type array function parameters with psycopg2?
> The situation is:
> create type mytype as
> i integer;
> t character varying;
> create function myfunc(in param mytype) as
> How can I call this function form psycopg2?
If you are able to call the function from psql, i.e. using a syntax such as:
=> select myfunc(array[(10,'foo'),(20,'bar')]::mytype);
then you have to pass a similar string to a cur.execute (I don't think
callproc is going to be useful). You can use for instance:
>>> cur.execute("select myfunc(%s::mytype)", ([('foo',10), ('bar',20)],))
# would call: "select myfunc(ARRAY[(E'foo', 10), (E'bar', 20)]::mytype)"
if you have some object you defined yourself instead of a list of
tuples of strings and ints, and want psycopg to automatically convert