- Mailing list pgsql-sql

From Mark Teper
Subject
Date
Msg-id CAMwSyGra+i1oL0pKgCv1WeE6GeBNhJJZTJ0bGxLNqJ0SFeEsVw@mail.gmail.com
Whole thread Raw
Responses Re: plpython transforms vs. arrays  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: plpython transforms vs. arrays  (Jiří Fejfar <jurafejfar@gmail.com>)
AW:  ("Sonnenberg-Carstens, Stefan" <ssonnenberg@ophardt.com>)
List pgsql-sql

Hi,

I'm trying to build some numerical processing algorithms on Postgres Array data types.  Using PL/Python I can get access to the numpy libraries but the performance is not great.  A guess is that there is a lot of overhead going from Postgres -> Python List -> Numpy and back again.

I'd like to test if that's the issue, and potentially fix by creating a C extension to convert directly from Postgres Array types to Numpy Array types.  I _think_ I have the C side somewhat working, but I can't get Postgres to use the transform.

What I have:

---

CREATE FUNCTION arr_to_np(val internal) RETURNS internal LANGUAGE C AS 'MODULE_PATHNAME', 'arr_to_np';

CREATE FUNCTION np_to_arr(val internal) RETURNS real[] LANGUAGE C AS 'MODULE_PATHNAME', 'np_to_arr';

CREATE TRANSFORM FOR real[] LANGUAGE plpythonu (

    FROM SQL WITH FUNCTION arr_to_np(internal),

    TO SQL WITH FUNCTION np_to_arr(internal)

);

CREATE FUNCTION fn (a integer[]) RETURNS integer

    TRANSFORM FOR TYPE real[]  

     AS $$  return a $$ LANGUAGE plpythonu;

----

The problem is this produces an error that transforms for type "real" doesn't work.  It doesn't seem to allow for transforms on array's as opposed to underlying types.  Is it possible to tell it to apply the transform to the array?  

Thanks,

Mark

pgsql-sql by date:

Previous
From: Mike LAZLO
Date:
Subject: Re: ERROR: missing FROM-clause entry for table "new"
Next
From: Tom Lane
Date:
Subject: Re: plpython transforms vs. arrays