Guest User

Untitled

a guest
Nov 27th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import psycopg2
  2.  
  3. conn=psycopg2.connect("dbname=guest user=guest password=guest")
  4. cur=conn.cursor()
  5.  
  6.  
  7.  
  8. def query1():
  9.  
  10. cur.execute("select id from taxi_services;")
  11. results=cur.fetchall()
  12. i=0
  13. tmp=""
  14. for row in results:
  15. tmp=int(row[0])
  16. cur.execute("insert into dw_taxis (taxi_id,n_taxi) values(%s,%s);",(i,tmp))
  17. conn.commit()
  18. i=i+1
  19. query2(tmp)
  20.  
  21. def query2(id):
  22. i=0
  23. cur.execute("select to_timestamp(initial_ts) from taxi_services where id=%s;",(id,))
  24. results=cur.fetchall()
  25. for row in results:
  26. tmp=""
  27. tmp=str(row[0])
  28. x=tmp.split('-')
  29. dia=x[2].split(" ")[0]
  30. ano=x[0]
  31. mes=int(x[1])
  32.  
  33. tri=mes%3
  34. print(ano,mes,dia,tri)
  35.  
  36.  
  37.  
  38.  
  39.  
  40. #query1()
  41. query2(7268)
  42.  
  43.  
  44.  
  45. cur.close()
Add Comment
Please, Sign In to add comment