I have python script saved as a text file named test.py on my Desktop.
I need to execute that script using PostgreSQL.
Currently I am trying to create PostgreSQL function:
CREATE FUNCTION database.test()
RETURNS VOID
AS $$
py /C:/Users/User1/Desktop/test.py
$$ LANGUAGE plpython3u
That gives me an error:
ERROR: SyntaxError: invalid syntax (<string>, line 3)could not compile PL/Python function "test"
ERROR: could not compile PL/Python function "test"
SQL state: 38000
Detail: SyntaxError: invalid syntax (<string>, line 3)
from sqlalchemy import create_engine
import pandas as pd
db_config = {'user': '******',
'pwd': '*******',
'host': '*******',
'port': ****,
'db': '*******'}
connection_string = 'postgresql://{}:{}@{}:{}/{}'.format(db_config['user'],
db_config['pwd'],
db_config['host'],
db_config['port'],
db_config['db'])
engine = create_engine(connection_string)
test_df = pd.DataFrame(index=[0,1], columns= ['A', 'B'], data = 0)
test_df\
.to_sql(
'test_2',
schema='database',
con=engine,
if_exists='replace',
index=False
)
Could someone tell me what am I doing wrong?
test.pyin the question as well?plpython3u