第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Psycopg2 - 不返回輸出的 SQL 腳本

Psycopg2 - 不返回輸出的 SQL 腳本

嗶嗶one 2022-08-25 15:20:39
我正在嘗試將一些參數(shù)作為變量傳遞給SQL腳本,但我在返回輸出時(shí)遇到問題。下面給出的是我的代碼:start_date = '2020-03-01' end_date = '2020-03-02'我將這些傳遞到下面的查詢中cursor.execute('select bill_number from table                  where created_at between {} and {}'.format(start_date, end_date))以上不返回任何輸出,但我知道此SQL腳本存在數(shù)據(jù)
查看完整描述

1 回答

?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊

執(zhí)行查詢后,您需要獲取結(jié)果:


records = cursor.fetchall()

不要用于SQL查詢非常重要,因?yàn)樗菀资艿絊QL注入攻擊;而是使用:format


query = "select bill_number from table where created_at between %s and %s"

cursor.execute(query, (start_date, end_date))

records = cursor.fetchall()

如果要添加篩選器,只需調(diào)整查詢并添加參數(shù):


query = "select bill_number from table where created_at between %s and %s and product=%s"

cursor.execute(query, (start_date, end_date, product))

為了使用列表作為參數(shù),您可以使用和:INtuple


>>> query = "select * from clients where added between %s and %s and score in %s"

>>> data = ('2019-01-01', '2020-03-01', tuple([1,2,3]))

>>> cursor.execute(query, data)

>>> rows = cursor.fetchall()

>>> len(rows)

32

>>> 

確保您閱讀了文檔,因?yàn)樗鼈儼S多有價(jià)值的信息。


查看完整回答
反對(duì) 回復(fù) 2022-08-25
  • 1 回答
  • 0 關(guān)注
  • 83 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)