Re: [GENERAL] pl/python composite type array as input parameter

2015-06-02 Thread Adrian Klaver
On 06/02/2015 12:33 PM, Filipe Pina wrote: Basically, in an (maybe-over)simplified example: CREATE OR REPLACE FUNCTION add_transaction(transaction core_transaction) RETURNS integer AS $$ DECLARE transaction2 core_transaction; BEGIN transaction.field1 := 'lapse’; transaction2.

Re: [GENERAL] pl/python composite type array as input parameter

2015-06-02 Thread Filipe Pina
Basically, in an (maybe-over)simplified example: CREATE OR REPLACE FUNCTION add_transaction(transaction core_transaction) RETURNS integer AS $$ DECLARE transaction2 core_transaction; BEGIN transaction.field1 := 'lapse’; transaction2.field2 := transaction.field2; transaction2.fi

Re: [GENERAL] pl/python composite type array as input parameter

2015-06-02 Thread Adrian Klaver
On 06/02/2015 03:10 AM, Filipe Pina wrote: HI Adrian, I had a typo in the email: INSERT INTO my_table VALUES(my_table.*); was actually INSERT INTO my_table VALUES(my_var.*); Aah, that is different:) So I meant to insert the variable I had in memory (dict representing a row), not the row

Re: [GENERAL] pl/python composite type array as input parameter

2015-06-02 Thread Filipe Pina
Thanks Rémi, Indeed I needed something more generic and easy to maintain (regarding table schema evolution) so I ended up going back to PL/PGSQL (for that specific function) in the meantime. > On 02/06/2015, at 09:41, Rémi Cura wrote: > > OUps, > > I forget another strategy I used : > instea

Re: [GENERAL] pl/python composite type array as input parameter

2015-06-02 Thread Filipe Pina
HI Adrian, I had a typo in the email: INSERT INTO my_table VALUES(my_table.*); was actually INSERT INTO my_table VALUES(my_var.*); So I meant to insert the variable I had in memory (dict representing a row), not the rows from the table.. > On 02/06/2015, at 01:44, Adrian Klaver wrote: > >

Re: [GENERAL] pl/python composite type array as input parameter

2015-06-02 Thread Rémi Cura
OUps, I forget another strategy I used : instead of having testp2(es employee[]) you can use testp2( names text[], salaries integer[], ages integer[]) This might be the solution with the less work, but it is absolutely terrible practice, because it will be hard to change you record type (evoluti

Re: [GENERAL] pl/python composite type array as input parameter

2015-06-02 Thread Rémi Cura
Hey, the only straight workaround I know (which is pretty bad) is to cast down your record to text. Then you have an array of text, which is manageable. For this you can either 'flatten' your record into a unique text, or cast each part of your record to text, then emulate an array of array (you n

Re: [GENERAL] pl/python composite type array as input parameter

2015-06-01 Thread Adrian Klaver
On 06/01/2015 07:42 AM, Filipe Pina wrote: Thanks for the reply anyway, it's a pity though, it'd be useful.. Another bump I've found along the pl/python road: insert ROWTYPE in table.. Maybe you have some hint on that? :) So, in PLPGSQL I can: DECLARE my_var my_table; BEGIN my_var.col1 :

Re: [GENERAL] pl/python composite type array as input parameter

2015-06-01 Thread Filipe Pina
Thanks for the reply anyway, it's a pity though, it'd be useful.. Another bump I've found along the pl/python road: insert ROWTYPE in table.. Maybe you have some hint on that? :) So, in PLPGSQL I can: DECLARE my_var my_table; BEGIN my_var.col1 := 'asd'; INSERT INTO my_table VALUES(my_table

Re: [GENERAL] pl/python composite type array as input parameter

2015-05-28 Thread Peter Eisentraut
On 5/18/15 10:52 AM, Filipe Pina wrote: > But one of the functions I need to create needs to accept an array of > records. PL/Python doesn't support that. Some more code needs to be written to support that. You did everything correctly. I don't know of a good workaround. -- Sent via pgsql-g

[GENERAL] pl/python composite type array as input parameter

2015-05-18 Thread Filipe Pina
Hello, I'm building an app in Django and I want to have some functions directly in postgres. I'd prefer to use pl/python for the functions as it'd look better in Django migration files (python code within python code, instead of using PLPGSQL). But one of the functions I need to create needs