I want to create postgresql function (CREATE FUNCTION) with PL/Python.
How do I convert from python datetime object to postgresql timestamp object in procedure?
Tell the prepare method the type of the parameter value, a timestamp, then pass a datetime value to the execute method:
create or replace function pytest()
returns timestamp as $$
from datetime import datetime
plan = plpy.prepare('select $1 as my_datetime', ['timestamp'])
rv = plpy.execute(plan, (datetime.now(),))
return rv[0]['my_datetime']
$$ language plpythonu;
select pytest();
pytest
----------------------------
2016-07-20 13:57:59.625991
create procedure-type call to pg?stored procedurein postgresql.