0

in this (vey condensed) query, how would one return the myfile_key from RETURNING?

CREATE OR REPLACE FUNCTION myfunction (src int, OUT result int) AS $$

plan = plpy.prepare("INSERT INTO myfile VALUES (nextval('seq_myfile'),$1,$2)
RETURNING myfile_key", ["integer","integer"] )

$$ LANGUAGE plpythonu;

(where the first field inserted is myfile_key)

The code doesn't return the value to output, and haven't been able to query it as a standard python result, as in:

result = rv[0]["myfile_key"] 
Charles
  • 50,943
  • 13
  • 104
  • 142
DrLou
  • 649
  • 5
  • 21

1 Answers1

0

I assume there is a call to plpy.execute missing in your code. You are in principle right to access the RETURNING columns like rv[0]["myfile_key"]. What's not working is the assignment to OUT parameters in PL/Python. I suggest that you rewrite your function without OUT parameters using a normal return statement.

Peter Eisentraut
  • 35,221
  • 12
  • 85
  • 90
  • Hello Peter! and thanks for your comment. Yes, I'm moving over to trying to use standard return statements for this. I've been using return for lots of things already; I somehow assumed the SQL 'RETURNS' could also be used in this context. (note: I _do_ have the call to plpy.execute; I was keeping this snippet as simple as possible!) – DrLou Aug 06 '11 at 13:11
  • ... but one other thought: Don't we _need_ the OUT return int bit of the declaration to prevent: ERROR: function result type must be specified ??? – DrLou Aug 06 '11 at 14:09
  • Actually, `OUT` parameters work just fine with PL/Python. It's not the language that handles them, after all. What's not working in PL/Python before PostgreSQL 9.1 is multiple `OUT` parameters. But that's not what you're doing here. So you really should provide more details. – Peter Eisentraut Dec 13 '12 at 21:46