-
[psycopg2] postgresql oid 에 대한 텍스트 가져오는 쿼리Programming Language/Python 2021. 11. 15. 18:05반응형
postgresql 에는 oid (object identifier) 가 있는데 테이블의 타입도 oid 로 관리하고 있다.
만약 python 에서 psycopg2 라이브러리를 사용한다면, 아래처럼 타입을 oid 로 받게 된다.
import psycopg2 conn = psycopg2.connect() cur = conn.cursor() cur.execute("select A, B from TEST") cur.description # (Column(name='A', type_code=20), Column(name='B', type_code=25))
이때, 해당 oid 에 대한 타입명을 알고 싶으면 아래 쿼리를 사용하면 알 수 있다.
# psql select 20::regtype::text; text -------- bigint (1개 행) select 25::regtype::text; text ------ text (1개 행)
반응형'Programming Language > Python' 카테고리의 다른 글
[python] CLOSE_WAIT 해결 방법 with TimeoutIterator (0) 2021.05.07 [Python] PLY (Python Lex-Yacc) 정리 - Yacc (0) 2021.04.28 [Python] PLY (Python Lex-Yacc) 정리 - Lex (0) 2021.04.28 문자열 암호화 / 복호화 with Python (0) 2021.02.01 RST (reStructuredText) & Sphinx 문법 정리 (0) 2019.12.09