简体   繁体   中英

Tabpy and Postgres

I'm experimenting with Tabpy in Tableau and writing data back to a database via a users selection in a dashboard.

My data connections work fine. However, I'm having trouble passing a variable back into the SQL query and getting an error saying the "variable name" doesn't exist in the table that I'm trying to update. Here is my code.

The error states that "dlr_status" does not exist on the table. This is the variable I'm trying to pass back to the query. The database is a Postgres database. Any help is greatly appreciated. I've been researching this for several days and can't find anything.

SCRIPT_STR("
    import psycopg2
    import numpy as np
    from datetime import date
    
    con = psycopg2.connect(
     dbname='edw',
     host='serverinfo',
     port='5439',
     user='username',
     password='userpassword')
    dlr_no_change = _arg1[0]
    dlr_status = _arg2[0]
    update_trigger = _arg3[0]
    sql = '''update schema.table set status = dlr_status where dlr_no = dlr_no_change'''
    
    if update_trigger == True:
        cur = con.cursor()
        cur.execute(sql)
        cur.commit",
ATTR([Dlr No]), ATTR([dlr_status]), ATTR([Update_Now]))

Your commit is missing "()". Or add a con.autocommit = True after creating the connection if you don't want to commit each step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM