psycopg2

How to access psycopg2 error wrapped in sqlalchemy error

蹲街弑〆低调 提交于 2019-12-20 06:19:11
问题 I'm uploading a pandas data frame to a table in Postgres using SQLalchemy and psycopg2. How do I access the psycopg2 error that is within the SQLalchemy error? I want to write an exception into my code only when it raises an error because of a null value in a column that violates not-null constraint. I know how to test for this exact pSQL error with psycopg2, but when I run my code it returns a SQLalchemy error. Here's the error: SQLalchemy.exc.IntegrityError: (psycopg2.errors

Sharing psycopg2 / libpq connections across processes

自作多情 提交于 2019-12-20 04:35:00
问题 According to psycopg2 docs: libpq connections shouldn’t be used by a forked processes, so when using a module such as multiprocessing or a forking web deploy method such as FastCGI make sure to create the connections after the fork. Following the link from that document leads to: On Unix, forking a process with open libpq connections can lead to unpredictable results because the parent and child processes share the same sockets and operating system resources. For this reason, such usage is

build SQL dynamic query with psycopg2 python library and using good conversion type tools

放肆的年华 提交于 2019-12-20 03:37:08
问题 I have some problem to design a good algorithm which use specification of psycopg2 library described here I want to build a dynamic query equal to this string : SELECT ST_GeomFromText('POLYGON((0.0 0.0,20.0 0.0,20.0 20.0,0.0 20.0,0.0 0.0))'); As you can see, my POLYGON object contain multiple point, read in a simple csv file some.csv which contain : 0.0;0.0 20.0;0.0 20.0;20.0 0.0;20.0 0.0;0.0 So i build the query dynamically, function of the number of line/data in the csv. Here my program to

trouble with python manage.py migrate -> No module named psycopg2

孤街浪徒 提交于 2019-12-20 02:11:29
问题 I am having some trouble with migrating Django using postgresql. This is my first time with Django, and I am just following the tutorial. As suggested on the Django website, I have created a virtualenv to run the Django project. Next, I created a postgresql database with these settings: In settings.py I have set these values for the database: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'django_tutorial', 'USER': 'johan', 'PASSWORD': '1234', } } When

Tuning Postgresql performance and memory use in a python workflow

♀尐吖头ヾ 提交于 2019-12-19 18:12:11
问题 I use Postgresql 9.4 for a model database. My table looks somewhat like this: CREATE TABLE table1 ( sid INTEGER PRIMARY KEY NOT NULL DEFAULT nextval('table1_sid_seq'::regclass), col1 INT, col2 INT, col3 JSONB); My Python 2.7 workflow often looks like this: curs.execute("SELECT sid, col1, col2 FROM table1") data = curs.fetchall() putback = [] for i in data: result = do_something(i[1], i[2]) putback.append((sid, result)) del data curs.execute("UPDATE table1 SET col3 = p.result FROM unnest(%s) p

I'm trying to install psycopg2 onto Mac OS 10.6.3; it claims it can't find “stdarg.h” but I can see it's there; what should I do?

时间秒杀一切 提交于 2019-12-19 08:23:34
问题 I'm desperately trying to successfully install psycopg2 but keep running into errors. The latest one seems to involve it not being to find "stdarg.h" (see code below). However I can see with my own eyes that a file called stdarg.h exists at /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h (where it claims it can't find anything) so I've no idea what to do about it. I'm running Mac OS 10.6.3 and within the last few days I've made sure I have all the latest OS developer tools. I have Python

I'm trying to install psycopg2 onto Mac OS 10.6.3; it claims it can't find “stdarg.h” but I can see it's there; what should I do?

旧时模样 提交于 2019-12-19 08:21:16
问题 I'm desperately trying to successfully install psycopg2 but keep running into errors. The latest one seems to involve it not being to find "stdarg.h" (see code below). However I can see with my own eyes that a file called stdarg.h exists at /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h (where it claims it can't find anything) so I've no idea what to do about it. I'm running Mac OS 10.6.3 and within the last few days I've made sure I have all the latest OS developer tools. I have Python

change database (postgresql) in python using psycopg2 dynamically

核能气质少年 提交于 2019-12-19 07:55:17
问题 Can anybody tell me how can I change database dynamically which I have created just now.. using the following code... I think during the execution of this code I will be in default postgres database (which is template database) and after new database creation I want to change my database at runtime to do further processing... from psycopg2 import connect from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT dbname = 'db_name' con = connect(user ='postgres', host = 'localhost', password =

change database (postgresql) in python using psycopg2 dynamically

ⅰ亾dé卋堺 提交于 2019-12-19 07:55:05
问题 Can anybody tell me how can I change database dynamically which I have created just now.. using the following code... I think during the execution of this code I will be in default postgres database (which is template database) and after new database creation I want to change my database at runtime to do further processing... from psycopg2 import connect from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT dbname = 'db_name' con = connect(user ='postgres', host = 'localhost', password =

Postgresql: Query 10x slower in a different client

Deadly 提交于 2019-12-19 05:59:46
问题 Looking at the postgres server log, I see that the exact same query on the same postgres server takes much longer (about 10x longer) when invoked from a Linux client or from a Windows client. The queries come from a Django application running on a Linux machine with 4GB RAM and on a Windows machine with 8GB RAM. Both pyhon environments have psycopg2 library version 2.4.4 to send requests to the same postgres server. Below are the postgres server logs The windows query (with time): 2013-06-11