繁体   English   中英

如何在python中安装PostgreSQL函数?

[英]how to install PostgreSQL functions in python?

我想通过Python修改PostgreSQL数据库。 就像将信息放入Python。 它将自动处理和分类PSQL数据库中的数据。 如何?

简单的问题:)

psycopg2是PostgreSQL的可靠包装器。 从文档:

DSN = 'dbname=test'

## don't modify anything below this line (except for experimenting)

class SimpleQuoter(object):
    def sqlquote(x=None):
        return "'bar'"

import sys
import psycopg2

if len(sys.argv) > 1:
    DSN = sys.argv[1]

print("Opening connection using dsn:", DSN)
conn = psycopg2.connect(DSN)
print("Encoding for this connection is", conn.encoding)

curs = conn.cursor()
curs.execute("SELECT 1 AS foo")
print(curs.fetchone())
curs.execute("SELECT 1 AS foo")
print(curs.fetchmany())
curs.execute("SELECT 1 AS foo")
print(curs.fetchall())

conn.rollback()

sys.exit(0)

curs.execute("SELECT 1 AS foo", async=1)

curs.execute("SELECT %(foo)s AS foo", {'foo':'bar'})
curs.execute("SELECT %(foo)s AS foo", {'foo':None})
curs.execute("SELECT %(foo)f AS foo", {'foo':42})
curs.execute("SELECT %(foo)s AS foo", {'foo':SimpleQuoter()})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM