1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import psycopg2 # Open a DB session dbSession = psycopg2.connect("dbname='socialmedia' user='postgres' password='aa'") dbSession.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) # Open a database cursor dbCursor = dbSession.cursor(); dbCursor.execute("select * from test_table where cityname = 'New York City'") serch_keyword = dbCursor.fetchone() print(serch_keyword) dbSession.close() dbCursor.close() |
返り値は以下になる
(1, ‘New York City’, Decimal(‘40.73’), Decimal(‘-73.93’))
コメントを残す