Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- conn = psycopg2.connect("dbname=northwind user=postgres password=pass1234 host=0.0.0.0")
- with conn:
- with conn.cursor() as curs:
- curs.execute("SELECT * FROM customers limit 10;")
- for row in curs:
- print('row:', row)
- name = input('Product name:')
- curs.execute("SELECT * FROM products where product_name=%s;", (name,))
- for row in curs:
- print('row:', row)
- # refactor to get product name as well
- curs.execute("SELECT * FROM order_details limit 10;")
- for row in curs:
- price, qty, discount = row[-3:]
- print(price * qty * (1 - discount))
- # take customers, group by city and send discounts to the largest city
- conn.close()
Add Comment
Please, Sign In to add comment