Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- url = 'postgres://username:[email protected]:1234/database'
- connection = psycopg2.connect(url)
- cursor.execute('SELECT * FROM table')
- first_record = cursor.fetchone() # though why not use LIMIT 1 for this?
- all_records = cursor.fetchall()
- print(first_record)
- for a in all_records:
- print(f'{a[0]}, {a[1]}, …')
- connection.close()
Add Comment
Please, Sign In to add comment