psycopg2

Psycopg2, Postgresql, Python: Fastest way to bulk-insert

て烟熏妆下的殇ゞ 提交于 2019-12-17 08:24:59
问题 I'm looking for the most efficient way to bulk-insert some millions of tuples into a database. I'm using Python, PostgreSQL and psycopg2. I have created a long list of tulpes that should be inserted to the database, sometimes with modifiers like geometric Simplify . The naive way to do it would be string-formatting a list of INSERT statements, but there are three other methods I've read about: Using pyformat binding style for parametric insertion Using executemany on the list of tuples, and

Only protocol 3 supported

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 03:57:56
问题 I try to configure Django with PostgreSQL on Windows 10. When I run server usually I get an error only protocol 3 supported but sometimes the server starts properly. I installed 32-bit Postgres 9.6 and psycopg2 2.7.1. In settings.py I have DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'django', 'PASSWORD': 'django', 'HOST': 'localhost', 'PORT': '5432', } } Do you know any solutions for the problem? 来源: https://stackoverflow.com

python manage.py dbshell doesn't find psycopg2 although it is installed and in path

爱⌒轻易说出口 提交于 2019-12-13 21:04:03
问题 I'd like to be issuing SQL commands via python manage.py dbshell but I get the error "CommandError: You appear not to have the 'sqlite3' program installed or on your path". From the python prompt I can import psycopg2 without getting any errors and psycopg2 appears to be in my python path. I'm trying django and my settings.py specifies "ENGINE": "django.db.backends.postgresql_psycopg2" Any help would be greatly appreciated, Thanks, Julian 回答1: when you run ./manage.py dbshell psql or sqlite3

I can't install Psycopg2 with Python3 on Mac. I've installed Python3 and pip3

若如初见. 提交于 2019-12-13 20:14:24
问题 I've tried to type this command: pip3 install --user psycopg2 psycopg2-binary Bash answers: ERROR: running install It appears you are missing some prerequisite to build the package from source. You may install a binary package by installing 'psycopg2-binary' from PyPI. If you want to install psycopg2 from source, please install the packages required for the build and try again. For further information please check the 'doc/src/install.rst' file (also at <http://initd.org/psycopg/docs/install

How to easy_install psycopg2 on windows 7?

自闭症网瘾萝莉.ら 提交于 2019-12-13 19:03:10
问题 While following this tutorial to setup osqa. I got into the line direct you to run: easy_install.exe psycopg2 I had located vcvarsall.bat under C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC and added the full path of it to %PATH% but still get the following error: error: Setup script exited with error: Unable to find vcvarsall.bat Here is the full cmd output: C:\>easy_install.exe psycopg2 Searching for psycopg2 Reading https://pypi.python.org/simple/psycopg2/ Reading http://initd.org

Odoo 12 in WSL - Psycopg2 doesn't get the right Port for PostgreSQL

眉间皱痕 提交于 2019-12-13 17:42:07
问题 I have installed Odoo 12 in Ubuntu 18.04 LTS using WSL for windows 10 Pro. Everything seems fine and service is running, but when I access the localhost I get Internal Server Error, and I get this error: 2019-09-05 06:52:07,596 309 ERROR ? werkzeug: Error on request: Traceback (most recent call last): File "/opt/odoo/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 303, in run_wsgi execute(self.server.app) File "/opt/odoo/.local/lib/python3.6/site-packages/werkzeug/serving.py",

jsonb with psycopg2 RealDictCursor

谁都会走 提交于 2019-12-13 14:31:11
问题 I have a postgresql 9.4 (aka mongodb killer ;-) ) and this simple schema : CREATE TABLE test (id SERIAL, name text, misc jsonb); now i populate this, if i make a select it will show something like id | name | misc 1 | user1 | { "age" : 23, "size" : "M" } 2 | user2 | { "age" : 30, "size" : "XL" } now, if i make a request with psycopg2, cur.execute("SELECT * FROM test;") rows = list(cur) i'll end up with [ { 'id' : 1, 'name' : 'user1', 'misc' : '{ "age" : 23, "size" : "M" }' }, { 'id2' : 2,

Get the the auto id for inserted row into Redshift table using psycopg2 in Python

旧街凉风 提交于 2019-12-13 13:11:38
问题 I am inserting a record into a Amazon Redshift table from Python 2.7 using psycopg2 library and I would like to get back the auto generate primary id for the inserted row. I have tried the usual ways I can find here or in other websites using google search, eg: conn=psycopg2.connect(conn_str) conn.autocommit = True sql = "INSERT INTO schema.table (col1, col2) VALUES (%s, %s) RETURNING id;" cur = conn.cursor() cur.execute(sql,(val1,val2)) id = cur.fetchone()[0] I receive an error on cur

Cannot get psycopg2 to work, but installed correctly. Mac OS

可紊 提交于 2019-12-13 11:35:58
问题 I'm trying to work with psycopg2 natively on Mac. It installs fine, with no errors at least, but when i import it get an error message. I've seen dozens of threads with similar issues and solutions that vary massively and just seem excessive for such a common module. can anyone help? Last login: Wed Oct 12 15:47:24 on console Gurmokhs-MBP:~ Gurmokh$ pip install psycopg2 Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /Library/Python/2.7/site-packages Gurmokhs-MBP:~

SQL string substitution error not enough arguments for format string

邮差的信 提交于 2019-12-13 07:54:27
问题 I'm trying to return a query to get all records that begin with string like a varibale i have so i do so : """select name from pos_order where name like '%s'||'%' order by id DESC limit 1"""%(darsh[0]) where darsh is something like that 'mostafa/' but it keep telling me not enough arguments for format string I don't know why. 回答1: Python tries to substitute both '%' characters in your sql. But it only has one value - darsh[0] - to use. Hence the error message, it is trying to fill in two