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
1 answer

unable to authenticate to postgresql via psycopg2

Hi guys I know this question has been asked many times but I've been searching through stackoverflow for hours and looking at similar issues but I haven't been able to figure out why I keep getting the authentication issue. Below is how I'm trying…
Mark
  • 113
  • 7
1
vote
1 answer

why does the the connection cursor need to be readable for a psycopg2 notification listening loop

psycopg2 provides some example code for using postgresql notify facilities import select import psycopg2 import psycopg2.extensions conn = psycopg2.connect(DSN) conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) curs =…
fgregg
  • 3,173
  • 30
  • 37
1
vote
1 answer

Is further psycopg2 SQL injection mitigtation possible?

I'm thinking about adding an additional layer of SQL injection mitigation in my usage of psycopg2 If cursor.execute is used properly and the parameters are passed like below this is not a concern. cursor.execute("SELECT * FROM employees WHERE name =…
Mike
  • 58,961
  • 76
  • 175
  • 221
1
vote
1 answer

No operator matches the given name and argument types. You might need to add explicit type casts

I am using PostgreSQL for storing username and their corresponding salted and hashed password but it is continuously giving me this error. LINE 1: ...egister where USERNAME = 'siddharth' and PASSWORD = '\x24326... …
Siddharth
  • 143
  • 2
  • 11
1
vote
0 answers

TypeError: execute_values() got an unexpected keyword argument 'fetch'

I am having an issue with creating an entry into a many-to-many postgresql db table with Flask, Flask-sqlalchemy, and flask-marshmallow. Below are my model setups. role_permissions = db.Table( 'role_permissions', db.Column('id', db.Integer,…
1
vote
1 answer

PostgresDB with psycopg2 query executing successfully but sometimes updating the record and sometimes not

I am trying to update PostgresDB with psycopg2 with below query, it is executing successfully but sometimes it is not updating the record (sometimes updating and sometimes not). Can someone help me? Below code printed 'Order status updated' but…
anilraj
  • 53
  • 7
1
vote
1 answer

Getting Django and PostgreSQL to work

I am trying to get Django and PostgreSQL to work. So far I am getting the following error when I run syncdb. .... django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2 The following is my…
bash-
  • 6,144
  • 10
  • 43
  • 51
1
vote
0 answers

Where is the missing postgres-plpython-12 for Ubuntu 20.04, required for psycopg2?

There is no available package for postgres-plpython-12 https://packages.ubuntu.com/search?keywords=postgresql-plpython The psycopg2 library does not work with plpython3 (or does it)? psycopg2.errors.UndefinedFile: could not access file…
Darren Weber
  • 1,537
  • 19
  • 20
1
vote
1 answer

Python list to PostgreSQL HSTORE via SQLAlchemy

I'd like to store Python dicts containing lists as HSTORE object in a PostgreSQL database using SQLAlchemy. Following my table class. from sqlalchemy.dialects.postgresql import HSTORE from sqlalchemy import Column, String from…
ZKDev
  • 315
  • 2
  • 9
1
vote
3 answers

How Python psycopg2 query in condition with uuid array

For given a table create table test_db ( id uuid ) In Python with library psycopg2, we can do query cursor.execute("select * from test_db where id in" + " ('5ed11bbf-ffd1-4124-ba3d-5e392dc9db96','14acfb5b-3b09-4728-b3b3-8cd484b310db')") But…
Yanbin
  • 124
  • 7
1
vote
1 answer

postgresSQL terminating abnormally

I am trying to update postgresSQL table with psycopg2 (python package) sometimes it is failing with below error. server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the…
anilraj
  • 53
  • 7
1
vote
1 answer

See sanitized sql query

The advised way to run a parameterized query with psycopg2, if I understand correctly, is to use the second argument to the execute method: SQL = "INSERT INTO authors (name) VALUES (%s);" data = ("O'Reilly", ) cur.execute(SQL, data) This will…
Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
1
vote
1 answer

How to query overlapping dates on Postgres DateRange field

I have a model with a PostgreSQL DateRange field: class MyModel(models.Model): date_range = DateRangeField() If I want to query this to see if another date overlaps, that's easy…
alias51
  • 8,178
  • 22
  • 94
  • 166
1
vote
1 answer

Complex SQL query works in Postgresql pgAdmin 4 but not Python

This query: select product.width, product.height from product inner join product_template on product.prodtempindex = product_template.prodtempindex inner join painting on painting.pntindex = product.pntindex where…
meejo57
  • 23
  • 5
1
vote
2 answers

Install psycopg2 on pypy3 docker image

I tried very hard to install psycopg2 on pypy3 docker image https://hub.docker.com/_/pypy This proved impossible... FROM pypy:3 WORKDIR / COPY . . RUN apt-get update RUN apt-get install libpq-dev gcc RUN apt-get -y install python3-dev RUN apt-get -y…
user3761555
  • 851
  • 10
  • 21
1 2 3
99
100