Questions tagged [psycopg2]

Psycopg is a PostgreSQL adapter for Python programming language. It implements PEP 249 with many extensions.

Psycopg is a PostgreSQL adapter for Python . It is a wrapper around the libpq library. Psycopg fully implements PEP 249. It is thread-safe. It supports asynchronous I/O, server-side cursors, COPY, large objects and two-phase commit. Psycopg is extensible with new adapters and typecasters.

Questions that relate directly to psycopg2 should receive this tag. If you are using a web framework, scientific library or ORM in conjunction with Psycopg2 be sure to include that information in your post, and consider adding tags for those libraries.

Psycopg can be easily installed on Linux or Mac, but lacks full support in Windows, though there is a port available. It requires some manual installation in a virtual environment.

Psycopg2 can be used to archive the state of objects, although it is often convenient to use an ORM (SQLAlchemy for example).

External Links

4351 questions
19
votes
3 answers

How to resolve the "psycopg2.errors.UndefinedTable: relation "auth_user" does not exist" when running django unittests on Travis

I'm using Travis for CI/CD as part of my Django app, with a postgresql database. (Django 2.1.4) The build consistently fails on Travis as soon as the tests run. I receive this error: psycopg2.errors.UndefinedTable: relation "auth_user" does not…
741852963
  • 479
  • 1
  • 3
  • 18
19
votes
2 answers

Cannot install psycopg2 on OSX 10.6.7 with XCode4

Trying to install psycopg2 on OSX results in the following: building 'psycopg2._psycopg' extension creating build/temp.macosx-10.6-universal-2.6 creating build/temp.macosx-10.6-universal-2.6/psycopg gcc-4.2 -fno-strict-aliasing -fno-common…
margusholland
  • 3,306
  • 1
  • 23
  • 30
19
votes
4 answers

uwsgi segmentation fault when serving a django application

I am trying to migrate a django application from one server to another. The application is working fine on the old server. On the new server, the application works fine when used using Django's runserver. To test the django application under…
len71
  • 321
  • 2
  • 6
19
votes
2 answers

Sqlalchemy: subquery in FROM must have an alias

How can I structure this sqlalchemy query so that it does the right thing? I've given everything I can think of an alias, but I'm still getting: ProgrammingError: (psycopg2.ProgrammingError) subquery in FROM must have an alias LINE 4: FROM (SELECT…
slashdottir
  • 7,835
  • 7
  • 55
  • 71
19
votes
1 answer

psycopg2: (col1, col2) IN my_list: ProgrammingError: syntax error at or near "ARRAY"

I want to execute this sql via psyopg2: select indexname from pg_indexes where (tablename, indexname) in ( ('tab1', 'index1'), ('tab2', 'index2') ); Here is the code: cursor.execute( 'select tablename, indexname from pg_indexes where…
guettli
  • 25,042
  • 81
  • 346
  • 663
19
votes
6 answers

How do I run psycopg2 on El Capitan without hitting a libssl error

I've got a python django dev setup on my mac and have just upgraded to El Capitan. I've got psycopg2 installed in a virtualenv but when I run my server I get the following error - django.core.exceptions.ImproperlyConfigured: Error loading psycopg2…
Aidan Ewen
  • 13,049
  • 8
  • 63
  • 88
19
votes
5 answers

Generate SQL statements with python

I need to generate a list of insert statements (for postgresql) from html files, is there a library available for python to help me properly escape and quote the names/values? in PHP i use PDO to do the escaping and quoting, is there any equivalent…
Jeffrey04
  • 6,138
  • 12
  • 45
  • 68
18
votes
8 answers

Apple M1: install psycopg2 package Symbol not found: _PQbackendPID

pg_config venv ❯ which pg_config /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config pip3 install -r requirements.txt requirements.txt venv ❯ cat requirements.txt -i…
lidashuang
  • 1,975
  • 4
  • 20
  • 22
18
votes
3 answers

PostgreSQL- ModuleNotFoundError: No module named 'psycopg2'

I can confirm psycopg2 is install (using conda install -c anaconda psycopg2) but the it seems psycopg2 cannot be imported to my python script or the interpreter is unable to locate it. I also tried installing using pip3, requirements are satisfied,…
arilwan
  • 3,374
  • 5
  • 26
  • 62
18
votes
2 answers

Error: could not determine PostgreSQL version from "10.4"

Complete output from command python setup.py egg_info: running egg_info creating pip-egg-info/psycopg2.egg-info writing pip-egg-info/psycopg2.egg-info/PKG-INFO writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt writing…
rislah
  • 197
  • 1
  • 2
  • 6
18
votes
2 answers

psycopg2: Can't adapt type 'UUID'?

I am using psycopg2 to try to insert an entry into a table where the type of the data is the Postgres type 'uuid'. According to this page, I should be able to directly use the Python type uuid.UUID, as in the following code: uuid_entry =…
Resquiens
  • 333
  • 1
  • 3
  • 9
18
votes
2 answers

DictCursor vs RealDictCursor

AFAIU and from docs, RealDictCursor is a specialized DictCursor that enables to access columns only from keys (aka columns name), whereas DictCursor enables to access data both from keys or index number. I was wondering why RealDictCursor has been…
comte
  • 3,092
  • 5
  • 25
  • 41
18
votes
1 answer

Where did the psycopg2 name come from?

Every time I write import psycopg2 I wonder why it is called psycopy2, because I always forget the true spelling? Is there any history I can know so that I could remember it clearly?
Joe Zhow
  • 833
  • 7
  • 17
18
votes
7 answers

postgresql: jsonb update multiple keys in one query

I have the following postgresql rows as JSONB row: {age:26} And I would like to replace it so that that i looks like this: {age: 30, city: "new york city"} How can I do this in postgressql? Someone metioned using jsonb_set(), but I haven't seen…
ApathyBear
  • 9,057
  • 14
  • 56
  • 90
18
votes
1 answer

Why is psycopg2 IntegrityError not being caught?

I have some code where I try to write to a database, and in some cases get an (expected) integrityerror due to a uniqueness constraint. I am trying to catch the error, but for some mysterious reason I cannot. My code looks like this (running in a…
Leo
  • 288
  • 1
  • 2
  • 9