我需要从一个 redshift database
基于 IF
用python编写的条件。
假设我有一张table CustomerID, SHipment Number, Invoice Station, ect
作为中的列 Redshift table
,我想从redshift表中获取所有记录,如果客户id存在,则应使用用户输入进行检查。
表名=shipmentinfo
列=customerid、billnumber、开票站、费用等。
python
import psycopg2
con=psycopg2.connect(dbname= 'datamodel', host='123',
port= '5439', user= 'bce', password= 'Ciz')
cur = con.cursor()
HWB = input("Enter the House Bill Number : ")
# if CustomerID = HWB:
cur.execute("SELECT source_system, file_nbr, file_date, CustomerID
FROM public.shipment_info where CustomerID = $HWB")
results = cur.fetchall()
cur.close()
con.close()
print(results)
1条答案
按热度按时间vbkedwbf1#
考虑用户输入值的参数化(否则就要冒臭名昭著的bobby表的风险)。