0

I have a Postgresql function as below:

CREATE OR REPLACE FUNCTION accdisvalues(thisdate date)
 RETURNS void AS
$BODY$
 Update my_table 
 Set 
 mycolumn = true
 where mydatecol = thisdate;
$BODY$
 LANGUAGE sql VOLATILE SECURITY DEFINER
 COST 100;
ALTER FUNCTION accdisvalues(date)
 OWNER TO myconnect;

Whenever I run it from PG AdminIII it runs perfectly and values are updated in the table.

I am trying to run it from Python 3 with the below code and the code runs without throwing an error but no update is done in the table. Could someone assist me troubleshoot what could be the 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 successfully for ' + setdate ,title="Input Status")
asked May 8, 2015 at 10:01
2
  • Is there some entry in the PG log file why the update fails? Commented May 8, 2015 at 10:25
  • Turns out after executing the cursor statement you need to run a conn.commit() to finish. Thank you very much for your assistance. Commented May 8, 2015 at 11:31

1 Answer 1

1

The full corrected Python code is 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 all changes to the DB
 easygui.msgbox(msg='Data loaded successfully for ' + setdate ,title="Input Status")

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

answered May 8, 2015 at 11:34
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.