Questions tagged [psycopg2]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
36 views

Insert Polars column with a dict to PostgreSQL with JSONB format

I'm trying to insert a Polars column containing dict in PostgreSQL by using the polar built-in write_database. During the insertion I would like that column formatted as JSONB in PostgreSQL to be more ...
Terence Bonin's user avatar
1 vote
1 answer
35 views

How can i plot a graph that has a value for each month displaying in the x label tick just the year? In Matplotlib.Pyplot

cur.execute( """ SELECT sum(value), Extract ('month' from dateOperation), Extract ('year' from dateOperation) FROM movimenti GROUP BY (Extract ('month' from dateOperation)), (Extract ('...
RandomGuy's user avatar
0 votes
0 answers
87 views

Postgres DB connection to FastAPI

I'm trying to connect a postgres DB with fastapi. My postgres DB is a docker contanier. My docker-compose is: version: "3.1" services: postgres: image: postgres container_name: ...
learning_afo's user avatar
0 votes
0 answers
43 views

Using named postgresql cursor in alembic migration results in psycopg2.errors.InvalidCursorName

I'm trying to write a function that will export large table to the csv file. This function will be run as a part of alembic migration. Note that I'm using PostgreSQL v12 and psycopg2 v2.9 and ...
Mariusz's user avatar
  • 25
0 votes
0 answers
30 views

Faced error for installing pccapg2 for pathm3.12 in the Linux (ubuntu) server [duplicate]

I want to install psycopg2 for Python 3.12 on Ubuntu. For installation, I am using the command: > python3.12 -m pip install psycopg2 But it shows this error: Collecting psycopg2 Downloading ...
Abdul Awal Nadim's user avatar
0 votes
0 answers
21 views

psycopg2 sql injection for: WHERE col IN ( 'val1', 'val2' , 'val3') [duplicate]

I want to allow my app user to look in my database for people living in countries of its choice. He can pass an array of countries to an api endpoint and receive corresponding people. I do the ...
Gaut's user avatar
  • 1,307
0 votes
0 answers
43 views

docker container crashes while connecting to postgresql database

I am running a docker container on kubernetes cluster. When the below code is executed, container crashes with the following error. import psycopg2 as psc pq_conn = psc.connect( database=****, ...
Dipu Cs's user avatar
  • 23
0 votes
0 answers
19 views

Redshift serverless - Django connection active all the time

I have Django application running which connects to postgres for basic django functionality/setup. But this application also connects to Redshift serverless using psycopg2 library. The problem is that ...
Manoj Kumar's user avatar
-1 votes
0 answers
27 views

Psycopg2 - no suitable image found

While trying to install the Python package psycopg2-binary, I get the error: Traceback (most recent call last): File "/Users/andrew/PycharmProjects/flask/app.py", line 1, in <module> ...
Name's user avatar
  • 1
0 votes
0 answers
29 views

How do I get a table from postgresql to be saved as a csv file in python running in airflow?

Apologies in advanced if the structure of the question is messy, as it is my first post here. I have this code below that runs without error if done in a code cell (Jupyter notebook), but when I tried ...
neranaiya's user avatar
0 votes
0 answers
45 views

Python not collecting data from postgres DB

I'm issuing a select statement to gather data from my postgres db with python like so: connection = psycopg2.connect( database=ps_db, user=ps_username, password=ps_password, host='hostname'...
charlopa24's user avatar
0 votes
0 answers
43 views

Issue with psycopg2 SSL Support when Converting Kivy App to APK

I've developed a Python Kivy app that runs fine on Windows. To convert it into an APK file for mobile devices, I'm using python-for-android with a GitHub workflow. However, attempting to launch the ...
Si110n's user avatar
  • 1
0 votes
1 answer
36 views

How does Psycopg2 handle sessions and transactions concurrency on high traffic apps?

I've been going through psycopg2 documentation to understand how it handles transactions and so on and so forth. I got that a transaction is created on a connection level, regardless of the cursor you ...
BrunoX's user avatar
  • 434
0 votes
1 answer
34 views

psycopg2 for Python 2.7

I am trying to run a jenkins job which runs on Python 2.7. The job clones a git repository in the Worspace. The repository has the 'site-packages' folder which contains the required packages. However, ...
Meghani Aadish's user avatar
0 votes
0 answers
63 views

SQLalchemy throwing a data conversion error whereas pgadmin has no trouble?

I initially altered my tables in PGadmin4, just going through some code refactoring where i wanted to instead of having my select statements in sql files to run on sqltools to do it through ...
j stevenage's user avatar
-1 votes
0 answers
31 views

psycopg2 layer for AWS lambda function built on python-3.11 [duplicate]

I have built a lambda layer of psycopg2 by using python-3.11 but it's not working Response { "errorMessage": "Unable to import module 'test': No module named 'psycopg2._psycopg'",...
Saquib Hussain's user avatar
-1 votes
1 answer
38 views

Failure to connect to PostgreSQL installed in portainer on a server from my local pC

I have synology DS920 at home connecter to my router. I installed portainer (container management) and started a container for PostgreSQL. From pgAdmin 4 I can see and access my database (for instance ...
Hotone's user avatar
  • 463
0 votes
0 answers
30 views

how to solve the psycopg2 and pillow installation problem on cpanel (

for hours I have been trying to deploy my django project on cpanel of lws, I created a python application and activated the virtual environment but as soon as I try to install the dependencies I ...
Roy Akany's user avatar
0 votes
1 answer
51 views

Import Error: cannot import name 'encodings' from 'psycopg2._psycopg'

I ran into this problem and Google doesn't give an answer... I have: Linux 3.10.0-1160.95.1.el7.x86_64; Django 3.2.6; Python 3.9; psycopg2 2.9.9; nginx/1.14.0; Log: [Wed Nov 15 11:20:13.904181 2023] [...
andrew_404's user avatar
0 votes
0 answers
70 views

Difference in record counts between my SQL editor and Python psycopg2 query

I am running the exact same redshift query copied from a sql editor to python. In python I have tested counts from pandas.read_sql and direct psycopg2 cursor.execute queries. On the SQL editor side, I ...
vizyourdata's user avatar
  • 1,426
0 votes
2 answers
157 views

poetry fails to install psycopg2-binary in python 3.12 (macos)

I cannot get psycopg2-binary package to install via poetry in python3.12. pyproject.toml [tool.poetry] name = "my_project" [tool.poetry.dependencies] psycopg2-binary = "*" [...
Marcel Wilson's user avatar
-2 votes
0 answers
71 views

library 'ssl' not found

ld: library 'ssl' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command '/usr/bin/clang' failed with exit code 1 -------------------------------...
Rohit Singh's user avatar
0 votes
1 answer
65 views

psycopg2: WHERE =ANY with multiple columns

PostgreSQL v14 Psycopg2 v2.9.3 I can do this in straight PostgreSQL / pgsql, however I can't seem to get it in Psycopg2. Given an example table: CREATE TABLE accounts ( id BIGINT GENERATED ...
Brooks's user avatar
  • 7,171
0 votes
1 answer
26 views

psycopg2 copy_expert - static column

I am trying to insert a large csv file into a PSQL table using psycopg2 copy_expert. However, I have 3 constraints: The original csv file has 7 columns and I only need to insert 5 of them I need to ...
Pierre-Alexandre's user avatar
0 votes
0 answers
55 views

issues in importing psycopg2 in AWS Glue

I am trying to connect redshift with the pyspark and thus using psycopg2, i am trying to import the same in the AWS Glue environment using two methods:- using --additional-python-module specifying ...
Aditya Sharma's user avatar
0 votes
0 answers
23 views

pycharm won't connect with database using psycopg2

hii yall im a first years compsci student and the thing im having trouble with is prob really easy to fix but I’ve genuinely tried everything I could find online already. anyways the problem is my ...
fairyprincess's user avatar
0 votes
1 answer
27 views

psycopg2: Insert numpy Array with NaNs into Table

The following code works fine to insert multidimensional numpy arrays into a table def adapt_numpy_array(numpy_array): return AsIs(numpy_array.tolist()) register_adapter(np.ndarray, ...
Tengrath's user avatar
0 votes
0 answers
33 views

Connection to PostgresSQL database closed in cPanel Flask app

I've developed a simple flask website that is using a remote PostgreSQL database. I've used sqlalchemy for defining the database and pyscopg for connecting to the database. I store the database URL, ...
jpmorr's user avatar
  • 530
0 votes
1 answer
78 views

RUN pip install not working in Dockerfile

i am stuck with this problem since several hours. I am trying to install psycopg2-binary via my Dockerfile: FROM jupyter/pyspark-notebook:latest RUN pip install psycopg2-binary COPY Spark.py /app/...
Kinggpuu's user avatar
2 votes
2 answers
74 views

Update values in table many times in minute

I need to call Update many times in minute. Is it the correct way to do this? I think not, cuz sometimes i get Exception - cursor already closed. I call this func from many threads, may be need to ...
Fresto's user avatar
  • 421
0 votes
0 answers
36 views

How can I install psycopg in requirements.txt when setting up pgAdmin development environment

The psycopg python package cannot install, and throws the following error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─&...
Kiplangat Stanley's user avatar
0 votes
0 answers
26 views

Dynamically build a type-hinted dict from a PostGreSQL DB read

Using python, PostGreSQL and psycopg2 to bridge the two. Currently building the CRUD functions. Crux of this question is on the Reads. Normally, the cursor fetch functions return data packaged in a ...
Joa's user avatar
  • 11
0 votes
0 answers
43 views

ImportError: DLL load failed while importing _psycopg: The specified module could not be found. and i use pip instal psycopg2 and the binary one

enter image description here I can't access tp psycopg2 no error and access to psycopg2 and not connected to django project show error no module found and server can't run and i use pip instal ...
Mohammad Alrubbi's user avatar
0 votes
0 answers
17 views

Issues with installation of Taguette on my local machine

Before installing taguette on a server, I wanted to ensure that I was able to have it up and running on my own machine using the docker tutorial of taguette (self-host-taguette). However I don't seem ...
user21297752's user avatar
0 votes
0 answers
63 views

Python: How use psycopg2.extras.execute_values for bulk insert

I'm trying to read parquet files with geometry in Well Known Blob into a PostgreSQL / PostGIS database using DUCK DB and psycopg2 This Works for a single row but is really slow SQL = """...
chig's user avatar
  • 1
0 votes
0 answers
18 views

Update multiple values with WHERE condition without using a for loop in psycopg

I have a pandas dataframe (df) with 2 columns, "item_code" and "item_price". I also have a larger postgresql table (items_table) that contains the same 2 columns. The item codes ...
Jareer Abuhmeidan's user avatar
-1 votes
1 answer
49 views

SyntaxError: ERROR: INSERT contains more target columns than

i had problem with Insert data from postgresql. API app my code: ` orders = [] @app.route('/client/order', methods=["POST", "OPTIONS"]) async def save_order(request): conn = ...
N Studio's user avatar
0 votes
0 answers
84 views

Cannot run pytest-postgresql with psycopg[binary]

I have tried running pytest-postgresql with a psycopg[binary] installation but I get a pytest_postgresql.exceptions.ExecutableMissingException: Could not found pg_config executable. Is it in systenm $...
Henrique Melo's user avatar
0 votes
1 answer
109 views

Unable to insert data into Postgres: psycopg2.ProgrammingError: can't adapt type 'dict' [duplicate]

I have tried any solution I have found here so far, however not a single one solved my issues of not being able to insert data into azure Postgres using psycopg2. This is the sample dict I have and ...
paul445's user avatar
  • 39
-1 votes
2 answers
59 views

Postgres connection not possible

i have a problem connecting to my postgres. It is running in my Docker properly but i am not able to connect via python to that container. Additionally i get no error message. "e" is empty. ...
Kinggpuu's user avatar
0 votes
1 answer
34 views

how to connect to specific schema with param: connection_factory in psycopy2 in python?

I already have the demo how to connect to specific schema with psycopg2 like : psycopg2.connect(host="localhost", port="5432", user="...
Grant.S's user avatar
  • 31
-1 votes
2 answers
66 views

Problem connecting to the PostgresSQL from Docker

Sample from class: try: conn = psycopg2.connect( database='ytbstatsdb', host='127.0.0.1', user='admin', password='admin123', port='...
Deer Me's user avatar
0 votes
0 answers
79 views

Is it safe to use Python % string operator to compose a Psycopg SQL query as long as values are passed separately to cursor.execute()

There is plenty of material, most notably the "Passing parameters to SQL queries" guide on psycopg.org, covering the security problems with using Python's + or % string operators to merge ...
Curtis Everingham's user avatar
0 votes
1 answer
40 views

With psycopg2, how to insert a NULL value to a db using an SQL command with string literals

Here is a Python expression using the psycopg2 library: if 'address' in data: address = data['address'] else: address = None cursor.execute(f"UPDATE public.mytable SET name = '{name}', ...
Fabian's user avatar
  • 239
-1 votes
1 answer
58 views

Using psycopg2, how can I receive output from `Raise Info 'foo'` in real time from psycopg2 query execution

I have a long-running stored procedure that uses Raise Info 'some status' to keep the client informed. The following is a dummy function illustrating this: Create or Replace Function Test_Raise() ...
RabidMutant's user avatar
3 votes
2 answers
799 views

psycopg2 importError Python3.12 on Windows

I have a python script that I built over the last 2 weeks using python3.10. The script did run fine 100s of times until I reinstalled python/modules. I recently upgraded to Python 3.12. I had to pip ...
Curly's user avatar
  • 31
0 votes
0 answers
87 views

OperationalError connection is bad: Cannot assign requested address Is the server running on that host and accepting TCP/IP connections?

I'm running a script that polls the db continuously checking for new rows that need to be processed. This script is running as a background process in a docker container which runs the flask app in ...
Maheedhar's user avatar
0 votes
1 answer
66 views

AWS Lambda unable to import module No module named 'psycopg2'

I'm trying to import psycopg2 in my lambda but I'm getting this error: [ERROR] Runtime.ImportModuleError: Unable to import module 'expire_invites': No module named 'psycopg2' I already downloaded the ...
Christopher Moura's user avatar
4 votes
1 answer
740 views

Is psycopg3 a fork of psycopg2, or a replacement upgrade?

I see references to both psycopg2 and psycopg3, but no clear guidance wrt a roadmap for transitioning between the two. I see that over time there is a large body of SO questions regarding psycopg2. ...
Mark Harrison's user avatar
1 vote
0 answers
42 views

Cannot use conda-forge to install psycopg2 library

Up until last week, I was running a powershell script to install python libraries on a server. I first install miniconda and then use conda to install my libraries like this: Start-Process "$...
gwydion93's user avatar
  • 1,745

1
2 3 4 5
89