【问题标题】:How to pass release_id into the query如何将 release_id 传递到查询中
【发布时间】:2022-01-10 12:38:31
【问题描述】:

以下是我目前的代码。如何将 release_id 传递到查询中?

import snowflake.connector
import sys 

cur = con.cursor()

try:
    cur.execute("select release_id, release_codes:transfer_date from food.fruit.apple order by release_id limit 100")
    release_rec=cur.fetchall()
   
    for row in release_rec:  
        #table2       
        cur.execute("SELECT count(*) from  from food.veggie.celery where release_id =row")
        one_row = cur.fetchone()
        print("count for viewing:",one_row[0])
        #table3
        cur.execute("SELECT count(*) from  from food.veggie.cucumber where release_id =row")
        one_row = cur.fetchone()
        print("count for ad_exposure:",one_row[0])
finally:
    cur.close()
cur.close()

【问题讨论】:

  • 哪个数据库适配器?
  • 在我格式化您的代码后,您是否有任何理由撤消我的更改?
  • @KlausD。雪花。导入雪花和导入系统
  • @KlausD。对不起,我的错。想通过添加来使事情更清楚,但显然不是。抱歉,不知道它是如何工作的!
  • 可以将这个 for 子句放在一个函数中,以 release id 作为参数,并根据需要多次调用它。

标签: python sql


【解决方案1】:

这应该可行:

cur.execute("SELECT count(*) from food.veggie.celery where release_id = %s", % row["release_id"])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 2021-01-20
    • 1970-01-01
    相关资源
    最近更新 更多