Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from osgeo import ogr
- conx = ogr.Open('PG:dbname=my_db user=postgres password=12345678')
- sql = 'SELECT * FROM table_name LIMIT 10;'
- for row in conx.ExecuteSQL(sql):
- print row.GetField(0) #gets first column, usually the id
- import psycopg2
- import sys
- conx = None
- conx = psycopg2.connect(database='my_db', user='postgres', password='12345678')
- curx = conx.cursor()
- #Prints version number
- curx.execute('SELECT version()')
- ver = curx.fetchone()
- print ver
- #Prints first row of table
- curx.execute('SELECT * FROM my_db LIMIT 1')
- onerow = curx.fetchone()
- print onerow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement