我很困惑我如何在Python中進行編碼。如何編碼sql選擇字符串
以下代碼來自pgsql命令行。
select * from consultation_tbl where consultation_status in ('S','C','R');
但在Python中,我不知道如何編碼。
chat_str = "\'S\',\'C\',\'R\'"
cursor.execute(" \
SELECT * FROM consultation_tbl
WHERE consultation_status IN (%s)", [chat_str])
請給我一個建議。
字符串替換可能導致SQL注入攻擊。 – lad2025
[python中的變量與SQL查詢]可能的重複(https://stackoverflow.com/questions/23217680/sql-query-with-variables-in-python) – wwii