Tabpy 和 Postgres

发布于 2025-01-11 00:09:46 字数 817 浏览 2 评论 0原文

我正在 Tableau 中试验 Tabpy,并通过仪表板中的用户选择将数据写回数据库。

我的数据连接工作正常。但是,我在将变量传递回 SQL 查询时遇到问题,并收到错误消息,指出我尝试更新的表中不存在“变量名称”。这是我的代码。

该错误表明表中不存在“dlr_status”。这是我试图传回查询的变量。该数据库是Postgres数据库。非常感谢任何帮助。我已经研究这个问题好几天了,但找不到任何东西。

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]))

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]))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼波传意 2025-01-18 00:09:46

您的提交缺少“()”。或者,如果您不想提交每个步骤,请在创建连接后添加 con.autocommit = True

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文