7

Is is possible to call a plpgsql function (or any PostgreSQL function) from a PL/Python function?

So, something like this:

CREATE FUNCTION somefunc() RETURNS void AS $$
DECLARE
    ...
BEGIN
    ...
END;
$$ LANGUAGE plpgsql;

And then use it here

CREATE FUNCTION pythonFunc() RETURNS void AS $$
    ...
    someFunc() #postgreSQL function
    ...
$$ LANGUAGE plpythonu;
four-eyes
  • 10,740
  • 29
  • 111
  • 220

1 Answers1

8
create function plpython_function()
returns void as $$

    plpy.execute('select plpgsql_function()')

$$ language plpythonu;

PL/Python Database Access

Clodoaldo Neto
  • 118,695
  • 26
  • 233
  • 260
  • How would you pass arguments on from the plpython_function to the plpgsql_function? The short answer to this would be, "import plpy and use plpy.quote_literal". My reply to that would be, "that's all very well, but 8.2 (actually, Greenplum) does not have plpy.quote_literal, it is actually quote_literal that I want to call!" Bootstrap problem. – PhilHibbs Jun 15 '17 at 12:20