【发布时间】:2020-08-03 15:12:03
【问题描述】:
我需要根据用 Python 编写的 IF 条件从 redshift database 中提取结果。
假设我有一个表,CustomerID, SHipment Number, Invoice Station, ect 作为 Redshift table 中的列,如果客户 ID 存在,我想从 Redshift 表中获取所有记录,应该通过用户输入进行检查。
- 表名 = ShipmentInfo
- COLUMNS = 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)
【问题讨论】:
标签: python sql postgresql amazon-redshift