NonplayerCharacter

Python psycopg2 PostgreSQL 101

Apr 20th, 2021 (edited)
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. import psycopg2
  2. url = 'postgres://username:[email protected]:1234/database'
  3. connection = psycopg2.connect(url)
  4. cursor.execute('SELECT * FROM table')
  5. first_record = cursor.fetchone()        # though why not use LIMIT 1 for this?
  6. all_records = cursor.fetchall()
  7. print(first_record)
  8. for a in all_records:
  9.     print(f'{a[0]}, {a[1]}, …')
  10. connection.close()
Add Comment
Please, Sign In to add comment