PyGreSQL 
http://www.pygresql.org


Python Database API Specification v2.0
http://www.python.org/dev/peps/pep-0249/




ex) SELECT

#!/usr/bin/python
# -*- coding: cp949 -*-


import pgdb

try:
    # DB 연결
    db = pgdb.connect(dsn = 'localhost:DB이름:UserID:Password')
    # cursor 객체생성
    cursor = db.cursor()
    query_string = 'SELECT * FROM 테이블이름'
    # query 실행
    cursor.execute(query_string)
    # query 실행 결과를 하나씩 빼먹는 과정
    row = cursor.fetchone()
    if row == None:
        print 'Empty result set from query => ', query_string
    else:
        while row != None:
            print '================='
            for i in range(len(row)):
                print '%s\t%s' % (i, row[i])
            row = cursor.fetchone()
        cursor.close()
except Exception, e:
    print str(e)

db.close()

'Python' 카테고리의 다른 글

Python용 최강 간단한 SSH 모듈.  (0) 2009.10.09
paramiko 설치  (0) 2009.10.09
[Python] Queue, Stack  (2) 2009.10.05
[Python] multi-thread에 queue 이용하기  (0) 2009.10.05
[Python] threading 객체사용  (5) 2009.10.05
Posted by bloodguy
,