In Postgres
, you can write a stored Procedure using the language PL/Python
able to connect in a bank Oracle
, enabling the exchange of data, see only:
CREATE FUNCTION oracle_foobar()
RETURNS SETOF tb_foobar AS
$BODY$
import cx_Oracle
conn = cx_Oracle.connect('usuario/senha@servidor_oracle/database')
cur = conn.cursor()
cur.execute('select * from tb_foobar')
ret = cur[:]
cur.close()
conn.close()
return ret;
$BODY$
LANGUAGE plpythonu;
Once with the function oracle_foobar()
created, you can use it to extract the data from a database Oracle
(tb_foobar
) and insert them into a database Postgres
(tb_xpto
), for example:
INSERT INTO tb_xpto ( a, b, c )
(SELECT a, b, c FROM oracle_foobar() WHERE c = 3);
In the Postgres
you can use the pg_cron
to execute the function in a scheduled manner.
Every day, at 10:00am
, for example:
SELECT cron.schedule('0 10 * * *', $$INSERT INTO tb_xpto ( a, b, c )(SELECT a, b, c FROM oracle_foobar() WHERE c = 3);$$ );
Lacobus, first of all thank you very much for the feedback. I will try to implement the solution.
– aleestevao
I downloaded the latest version of Python 3.6.5, but I’m not able to import the cx_Oracle module into the Python interpreter. ------------- Traceback <Most recent call last> File "<stdin>", line1, in <module> Modulenotfounderror: No module named 'cx_Oracle' --------------
– aleestevao