Skip site navigation (1) Skip section navigation (2)

Passing tabular data around using python functions

From: Achim Domma <domma(at)procoders(dot)net>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Passing tabular data around using python functions
Date: 2012-07-30 12:33:39
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers

I'm just trying to figure out what's possible with Postgresql and Python. One thing that's important for me, would be to pass result sets around to process them further. I have a table like this:

create table fps (
	docid integer,
	conceptid integer,
	rank float4

And the following function:

create or replace function vectormatch(data fps[])
	returns table(docid integer, weigth float4)
as $$
$$ language plpythonu;

I call the function like this:

select * from vectormatch(array(select (docid,conceptid,rank)::fps from fps where docid = 4205591))

and get the following output:

NOTICE:  <type 'list'>
CONTEXT:  PL/Python function "vectormatch"
NOTICE:  ['(4205591,1,1)', '(4205591,1219,1)', ...]
CONTEXT:  PL/Python function "vectormatch"

I'm quite surprised that there are strings in the list and not tuples!? I tried my best, but I have no idea what I might be doing wrong. The main purpose of my sample/experiment is, to pass the results of a query to a function and to process it there. Any hint would be very appreciated.



pgsql-hackers by date

Next:From: Gabriele BartoliniDate: 2012-07-30 15:12:38
Subject: Re: [PATCH] Support for foreign keys with arrays
Previous:From: Simon RiggsDate: 2012-07-29 19:48:53
Subject: Re: New statistics for WAL buffer dirty writes

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group