Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. from osgeo import ogr
  2. conx = ogr.Open('PG:dbname=my_db user=postgres password=12345678')
  3.  
  4. sql = 'SELECT * FROM table_name LIMIT 10;'
  5. for row in conx.ExecuteSQL(sql):
  6. print row.GetField(0) #gets first column, usually the id
  7.  
  8. import psycopg2
  9. import sys
  10.  
  11. conx = None
  12. conx = psycopg2.connect(database='my_db', user='postgres', password='12345678')
  13. curx = conx.cursor()
  14.  
  15. #Prints version number
  16. curx.execute('SELECT version()')
  17. ver = curx.fetchone()
  18. print ver
  19.  
  20. #Prints first row of table
  21. curx.execute('SELECT * FROM my_db LIMIT 1')
  22. onerow = curx.fetchone()
  23. print onerow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement