Questions tagged [psycopg3]

Use this tag for questions about the psycopg3 Postgresql connector package for Python, a new implementation of the psycopg2 package.

psycopg3 is a new implementation of the Postgresql connector for Python.

External links

70 questions
25
votes
2 answers

ImportError "no pq wrapper available" when importing psycopg3

I installed pyscopg3 on my venv using pip install psycopg[binary] as per the documentation but I still get an import error: Exception has occurred: ImportError no pq wrapper available. Attempts made: - couldn't import psycopg 'c' implementation: No…
ericshaaan
  • 251
  • 1
  • 3
  • 5
11
votes
2 answers

Creating an SQLAlchemy engine based on psycopg3

I need to upgrade the following code to some equivalent code based on psycopg version 3: import psycopg2 from sqlalchemy import create_engine engine = create_engine('postgresql+psycopg2://', creator=connector) This psycopg2 URL worked like a…
swiss_knight
  • 5,787
  • 8
  • 50
  • 92
7
votes
4 answers

How do I get libpq to be found by ctypes find_library?

I am building a simple DB interface in Python (3.9.9) and I am using psycopg (3.0.7) to connect to my Postgres (14.1) database. Until recently, the development of this app took place on Linux, but now I am using macOS Monterey on an M1 Mac mini.…
eslukas
  • 245
  • 2
  • 8
5
votes
5 answers

Unable to import module 'lambda_function': No module named 'psycopg2._psycopg aws lambda function

I have installed the psycopg2 with this command in my package folder : pip install --target ./package psycopg2 # Or pip install -t ./package psycopg2 now psycopg2 module is in my package and I have created the zip and upload it in AWS lambda. In my…
Jaskaran Singh
  • 145
  • 1
  • 10
3
votes
2 answers

How to stop a PostgreSQL query if it runs longer than the some time limit with psycopg?

In Python is library psycopg and with that I can do queries. I have an array with texts and I just iterate over them and run query to find this text in postgres. But some time the query takes so much time to execute and in that moment I want to…
Dmiich
  • 325
  • 2
  • 16
3
votes
1 answer

Psycopg3: passing a list as parameter for IN statement using named arguments

How can I pass a list to an IN statement in a query using psycopg's named arguments? Example: cur.execute(""" SELECT name FROM users WHERE id IN (%(ids)s) """, {"ids": [1, 2, 3]}) When I do that, I get the…
Leonardo Freua
  • 123
  • 1
  • 1
  • 7
3
votes
1 answer

Return json/dictionary from psycopg3 SELECT query

I've been asked to migrate a program from psycopg2 to psycopg3. In this program they use with connection.cursor(cursor_factory=RealDictCursor) as cursor: to obtain a dictionary that's later turned into a JSON file. My problem is that RealDictCursor…
neresi3
  • 31
  • 1
3
votes
3 answers

Copying CSV to PostgreSQL database using Psycopg3 in Python

I'm having a little difficulty understanding appropriate syntax for the psycopg3 library in Python. I'm trying to copy the contents of a .csv file into my database. The PostgreSQL documentation indicates copy should be written as follows: COPY…
Caritas
  • 45
  • 3
2
votes
2 answers

Using a buffer to write a psycopg3 copy result through pandas

Using psycopg2, I could write large results as CSV using copy_expert and a BytesIO buffer like this with pandas: copy_sql = "COPY (SELECT * FROM big_table) TO STDOUT CSV" buffer = BytesIO() cursor.copy_expert(copy_sql, buffer,…
FlipperPA
  • 13,607
  • 4
  • 39
  • 71
2
votes
0 answers

Should you share psycopg3 AsyncConnections between tasks in Python?

Psycopg3 supports async connections and async cursors. I have multiple writer tasks writing to a database. Should I pass each of those tasks the same AsyncConnection? If not, should I pass them the same AsyncCursor? Or should I make a new connection…
2
votes
1 answer

copying a table across servers with psycopg3

I'm working from and example in the psycopg3 documentation to copy a table from one database to another: link dsn_src = 'postgresql:///dev_db' dsn_tgt = 'postgresql:///prod_test' with psycopg.connect(dsn_src) as conn1, psycopg.connect(dsn_tgt) as…
user1290426
  • 153
  • 3
  • 7
2
votes
0 answers

Psycopg3 won't install on CentOS

I'm having issues installing Psycopg3 in a Docker image with python 3.7.3, pip 22.0.4 and CentOS Linux release 7.8.2003 (Core). When I run pip install psycopg[binary] I get the following messages and errors: Collecting psycopg[binary] Downloading…
Dula
  • 1,404
  • 1
  • 14
  • 29
2
votes
2 answers

Mashed-up emojis stored in a Postgres database not returned as single emoji using Python 3.9 with psycopg3. For example ‍ returned \u200d

I am reading text containing emojis from a Postgres 13 database. Turns out that my Python/psycopg query does not decode/return the text as I would expect. Via Postgres psql client Within postgres:13 container select description from profile WHERE…
smile2day
  • 1,585
  • 1
  • 24
  • 34
2
votes
1 answer

How to create a database using psycopg3?

This does not work: conn = psycopg.connect(dsn) conn.execute("CREATE DATABASE test") Here is the documentation about transactions in psycopg3: https://www.psycopg.org/psycopg3/docs/basic/transactions.html The most important statement for this…
nagylzs
  • 3,954
  • 6
  • 39
  • 70
1
vote
1 answer

Passing nested tuple to VALUES in psycopg3

I'm trying to updates some psycopg2 code to psycopg3. I'm trying to do a selection based on a set of values passed from Python (joining with an existing table). Without the join, a simplified example is: with connection.cursor() as cur: sql =…
xioxox
  • 2,526
  • 1
  • 22
  • 22
1
2 3 4 5