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
1
vote
0 answers

syntax error when trying to insert list of tuples using psycopg2

I am trying to get psycopg2 to accept the list of tuples I'm inputting but it is failing because the tuples are inside a list with [] brackets and I have tried to convert the list to a tuple so it's a tuple of tuples to no avail. Here is a sample of…
Justin Benfit
  • 423
  • 3
  • 11
1
vote
1 answer

Installing psycopg2 on M1

First of all, I know there are many similar questions already out there on SO. But none of them are working for me. I'm using a 2020 Macbook Air with an Apple M1 chip installed. I need psycopg2 to run my postgres Django database. psycopg2 just isn't…
Robo
  • 660
  • 5
  • 22
1
vote
1 answer

Python psycopg2 - Select query takes long time randomly

I am working on a task where I need to loop through a bunch of IDs and fetch relevant data from the PgSQL server 12.7. I have added a for loop in python and all the relevant code to connect to the database using psycopg2 version 2.9.1 connectStr =…
Sanket Kelkar
  • 129
  • 2
  • 9
1
vote
0 answers

What causes psycopg2.error.programlimitexceeded to occur?

I was inputting data into postgresql table using python sqlalchemy function. Currently, about 27 billion data have been entered, but the following error has occurred since then. sqlalchemy.exc.OperationalError: (psycopg2.errors.ProgramLimitExceeded)…
Hyungsik Jo
  • 146
  • 1
  • 14
1
vote
1 answer

psycopg2.OperationalError: SSL SYSCALL error: Connection reset by peer (0x00002746/10054) FATAL: no pg_hba.conf entry for host user database

I have changed nothing about my computer - I have, however, left the US for Germany for about two weeks. I can not connect to my database, while on my remote server I can. Is this some odd DNS issue? My coworker in the states can access it…
1
vote
1 answer

Why is my psycopg2 query failing with `psycopg2.errors.InternalError_: Assert`?

I'm running psycopg2 on Python 3.9, querying a Redshift table. I'm querying a table with a SELECT * passed to the cursor.execute() method: query = 'select * from my_schema.my_table;' cursor = connection.cursor(cursor_factory=RealDictCursor) #…
Brass
  • 56
  • 4
1
vote
1 answer

django/postgres: Transaction managed block ended with pending COMMIT/ROLLBACK

I want to run manage.py sqldiff myapp (command from django extension), but I get the following error: Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File…
Hoff
  • 38,776
  • 17
  • 74
  • 99
1
vote
1 answer

Concurrent updates with psycopg2

On a server, I have an API which is called by one or multiple clients. The server can receive, almost at the same time, multiple update instructions for the same PostgreSQL attribute. These requests do not arrive at the exact same time, and I would…
olivaw
  • 351
  • 1
  • 8
1
vote
2 answers

Will psycopg2 cursor.fetchmany() see concurrent committed transactions?

Consider the following code: import psycopg2 conn = psycopg2.connect(**credentials) cur = conn.cursor() cur.execute('select * from some_table') # Imagine some_table to be a very big table while True: rows = cur.fetchmany(1000) if not…
1
vote
0 answers

Type cast error with postgresql using python

import psycopg2 conn=None try: conn=psycopg2.connect(database="LIS", user="postgres",password="postgres",host="localhost",port=5432) except: print("Unable to connect") if conn: id="FCS01" cur=conn.cursor() query=""" SELECT…
1
vote
0 answers

Context manager with psycopg2 cursor doesn't tally

Hi from the documentation it says that the connection will not close with the psycopg2 cursor when used with a context manager (which typically does that for us). However, the results are quite different for a function im currently using, can…
KiatHao
  • 11
  • 2
1
vote
1 answer

How can I install psycopg2 or psycopg2-binary on cPanel hosting?

I'm trying to set up a Python / Flask app with PostgreSQL on new cPanel hosting server that I have just purchased. I've set up a virtualenv and managed to get all of my dependencies installed with pip install -r requirements.txt I cannot get…
user17507778
1
vote
1 answer

Batch upsert multiple rows with psycopg2

I need to upsert (INSERT ... ON CONFLICT DO UPDATE) multiple rows at once into a postgreSQL database using psycopg2. Essentially, I have a list of tuples representing "rows", and I need to insert them into the database, or update the database if…
jack.py
  • 362
  • 8
  • 23
1
vote
0 answers

How does psycopg2's connection_factory work?

Can someone explain what psycopg2's connection_factory is and how to use it? I've been looking at a project's code that connects to postgres via the connection_factory and I am at a lost. I have looked at the docs,…
Mark
  • 113
  • 7
1
vote
2 answers

psycopg2-binary installation into a virtual environment fails when trying to compile source code

I am trying to install psycopg2-binary into my Django project. I am using a virtual environment and the command I'm running is pip install psycopg2-binary However, I'm getting a massive error message, the gist of it is this: Error: pg_config…
Sundraw
  • 207
  • 2
  • 11