I need to extract results from a redshift database based on an IF condition written in Python.
Suppose I have a table with CustomerID, SHipment Number, Invoice Station, ect as columns in Redshift table, I want to get all the records from Redshift table if customer ID exists which should be checked with user input.
- TABLE NAME = ShipmentInfo
- COLUMNS = CustomerID, BillNumber, Invoicing Station, Charges, etc.
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)