Call plpgsql Function from a PL/Python Function in PostgreSQL
Asked Answered
S

1

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;
Siegbahn answered 24/1, 2017 at 11:22 Comment(0)
A
8
create function plpython_function()
returns void as $$

    plpy.execute('select plpgsql_function()')

$$ language plpythonu;

PL/Python Database Access

Anytime answered 24/1, 2017 at 11:48 Comment(1)
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.Gisser

© 2022 - 2024 — McMap. All rights reserved.