Personal tools
You are here: Home Pythonレシピブック その他 PostgreSQLの操作
Views
Actions
  • State: Published

PythonスクリプトからSQLを発行する。

# python:

 >>> import psycopg
 >>> cnx = psycopg.connect("user=postgres dbname=ping")
 >>> cr = cnx.cursor()
 >>> cr.execute("select count(*) from pingupdate")
 >>> result = cr.fetchall()
 >>> print result
 [(1195L,)]
 >>> result = result[0]
 >>> print result
 (1195L,)
 >>> count_entries = result[0]
 >>> print count_entries
 1195