psycopg2

psycopg2 : cursor already closed

让人想犯罪 __ 提交于 2020-02-19 09:51:08
问题 I am using psycopg2 2.6.1 . I have a bunch of queries that I need to execute in sequence. conn = psycopg2.connect(database=redshift_database, user=redshift_user, password=os.environ.get("PGPASSWORD"), host=redshift_cluster, port=redshift_port) cursor = conn.cursor() queries = [q1, q2, q3....] ## a list of queries for query in queries: try: cursor.execute(query) except: print e.message Suppose q1 fails with SSL connection has been closed unexpectedly . Then my rest of the queries also fail

psycopg2 : cursor already closed

馋奶兔 提交于 2020-02-19 09:48:12
问题 I am using psycopg2 2.6.1 . I have a bunch of queries that I need to execute in sequence. conn = psycopg2.connect(database=redshift_database, user=redshift_user, password=os.environ.get("PGPASSWORD"), host=redshift_cluster, port=redshift_port) cursor = conn.cursor() queries = [q1, q2, q3....] ## a list of queries for query in queries: try: cursor.execute(query) except: print e.message Suppose q1 fails with SSL connection has been closed unexpectedly . Then my rest of the queries also fail

Is there any problem installing psycopg2 in virtualenv on MacOS catalina with PostgreSQL 12.1 installed?

拟墨画扇 提交于 2020-02-06 09:27:05
问题 I am having this message: Collecting psycopg2 Using cached https://files.pythonhosted.org/packages/84/d7/6a93c99b5ba4d4d22daa3928b983cec66df4536ca50b22ce5dcac65e4e71/psycopg2-2.8.4.tar.gz Building wheels for collected packages: psycopg2 Building wheel for psycopg2 (setup.py) ... error ERROR: Command errored out with exit status 1: command: /Users/mohsen/.virtualenvs/jalas-env/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/vh/0

python连接Greenplum数据库

邮差的信 提交于 2020-02-02 05:55:37
配置greenplum客户端认证 配置pg_hba.conf cd /home/gpadmin/gpdbdata/master/gpseg-1 vim pg_hba.conf 增加 host all gpadmin 10.1.201.55/32 trust [gpadmin@ gpseg-1]$ export PGDATA=/home/gpadmin/gpdbdata/master/gpseg-1 [gpadmin@ gpseg-1]$ pg_ctl reload -D $PGDATA server signaled 使用Psycopg2访问数据库 Psycopg2 是 Python 语言下最常用的连接PostgreSQL数据库连接库,Psycopg2 的底层是由 C 语言封装 PostgreSQL 的标准库 libpq 实现的, 运行速度非常快,Psycopg2支持大型多线程应用的大量并发Insert和Update操作,Psycopg2完全兼容 DB API 2.0  安装Psycopg2 pip install psycopg2 Psycopg2使用参考文档 http://initd.org/psycopg/docs/index.html Psycopg2 连接PostgreSQL数据库接口 Psycopg2提供的操作数据库的两个重要类是 Connection , Cursor

How can SQLAlchemy be taught to recover from a disconnect?

为君一笑 提交于 2020-01-30 21:36:14
问题 According to http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html#disconnect-handling-pessimistic, SQLAlchemy can be instrumented to reconnect if an entry in the connection pool is no longer valid. I create the following test case to test this: import subprocess from sqlalchemy import create_engine, event from sqlalchemy import exc from sqlalchemy.pool import Pool @event.listens_for(Pool, "checkout") def ping_connection(dbapi_connection, connection_record, connection_proxy): cursor = dbapi

How can SQLAlchemy be taught to recover from a disconnect?

柔情痞子 提交于 2020-01-30 21:30:42
问题 According to http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html#disconnect-handling-pessimistic, SQLAlchemy can be instrumented to reconnect if an entry in the connection pool is no longer valid. I create the following test case to test this: import subprocess from sqlalchemy import create_engine, event from sqlalchemy import exc from sqlalchemy.pool import Pool @event.listens_for(Pool, "checkout") def ping_connection(dbapi_connection, connection_record, connection_proxy): cursor = dbapi

django postgres could not connect to server

老子叫甜甜 提交于 2020-01-25 17:51:35
问题 hi im working on a django project with virtualenv that is using the following Django==1.7.6 argparse==1.2.1 psycopg2==2.6 wsgiref==0.1.2 but when i try python manage.py runserver it gives me this error Performing system checks... System check identified no issues (0 silenced). Unhandled exception in thread started by <function wrapper at 0x7f0574e8c0c8> Traceback (most recent call last): File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/utils/autoreload.py", line

django postgres could not connect to server

怎甘沉沦 提交于 2020-01-25 17:51:31
问题 hi im working on a django project with virtualenv that is using the following Django==1.7.6 argparse==1.2.1 psycopg2==2.6 wsgiref==0.1.2 but when i try python manage.py runserver it gives me this error Performing system checks... System check identified no issues (0 silenced). Unhandled exception in thread started by <function wrapper at 0x7f0574e8c0c8> Traceback (most recent call last): File "/home/marashen/.virtualenvs/192/local/lib/python2.7/site-packages/django/utils/autoreload.py", line

safely specifying 'order by' clause from user input in python / postgresql / psycopg2

三世轮回 提交于 2020-01-25 04:36:20
问题 i feel like this is a stupid question but i can't find anything anywhere. I want to build an SQL query using psycopg2 where the user specifies the sort / order by column.. client-side its a javascript grid of data offering sorting / paging etc. normal substitution practice doesn't work: (note the E'xx') cur.mogrify('select * from table offset %s limit %s order by %s', [0,5,'sort_column']) >>> "select * from table offset 0 limit 5 order by E'sort_column'" short of cleansing / substituting the