How to execute a Postgresql function from Python -


i have postgresql function below:

create or replace function accdisvalues(thisdate date)   returns void $body$     update my_table      set      mycolumn = true     mydatecol = thisdate; $body$   language sql volatile security definer   cost 100; alter function accdisvalues(date)   owner myconnect; 

whenever run pg adminiii runs , values updated in table.

i trying run python 3 below code , code runs without throwing error no update done in table. assist me troubleshoot problem? many thanks.

import easygui import dbconnex     setdate = '30-dec-2014'     accdisupdate_fn = "select accdisvalues('" + setdate + "');"     print(accdisupdate_fn)     cursor = dbconnex.conn.cursor()     cursor.execute(accdisupdate_fn)     easygui.msgbox(msg='data loaded ' + setdate ,title="input status") 

the full corrected python code below:

import easygui import dbconnex     setdate = '30-dec-2014'     accdisupdate_fn = "select accdisvalues('" + setdate + "');"     print(accdisupdate_fn)     cursor = dbconnex.conn.cursor()     cursor.execute(accdisupdate_fn)     **dbconnex.conn.commit** #pushes changes db     easygui.msgbox(msg='data loaded ' + setdate ,title="input status") 

see here: http://initd.org/psycopg/docs/connection.html#connection.commit


Comments