Guest User

Untitled

a guest
Jan 31st, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import psycopg2
  2.  
  3.  
  4. conn = psycopg2.connect("dbname=northwind user=postgres password=pass1234 host=0.0.0.0")
  5.  
  6. with conn:
  7. with conn.cursor() as curs:
  8.  
  9. curs.execute("SELECT * FROM customers limit 10;")
  10. for row in curs:
  11. print('row:', row)
  12.  
  13. name = input('Product name:')
  14. curs.execute("SELECT * FROM products where product_name=%s;", (name,))
  15. for row in curs:
  16. print('row:', row)
  17.  
  18. # refactor to get product name as well
  19. curs.execute("SELECT * FROM order_details limit 10;")
  20. for row in curs:
  21. price, qty, discount = row[-3:]
  22. print(price * qty * (1 - discount))
  23.  
  24. # take customers, group by city and send discounts to the largest city
  25.  
  26.  
  27. conn.close()
Add Comment
Please, Sign In to add comment