我已经开始psycopg2
运行,我可以成功查询我的数据库的表。这是查询表的工作示例my_table
:
import psycopg2
try:
conn_string="dbname='my_dbname' user='user' host='localhost' password='password'"
print "Connecting to database\n->%s" % (conn_string)
conn = psycopg2.connect(conn_string)
print "connection succeeded"
except:
print "no connection to db"
cur = conn.cursor()
try:
cur.execute(""" SELECT * from my_table; """)
records = cur.fetchall()
cur.close()
except:
print "Query not possible"
问题:如何my_view
在同一个数据库中查询视图,让它被调用my_dbname
?