■ Cursor 클래스의 execute/fetchall 메소드를 사용해 데이터를 조회하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 |
import psycopg2 with psycopg2.connect("host='192.168.29.118' dbname='testdb' user='testuser1' password='test1234'") as connection: with connection.cursor() as cursor: cursor.execute("SELECT * FROM test") resultList = cursor.fetchall() for result in resultList: print(result) |
▶ requirements.txt
1 2 3 |
psycopg2-binary==2.9.9 |