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

Psycopg2/PostgreSQL 11.9: Syntax error at or near "::" when performing string->date type cast

I am using psycopg2 to create a table partition and insert some rows into this newly created partition. The table is RANGE partitioned on a date type column. Psycopg2 code: conn = connect_db() cursor = conn.cursor() sysdate =…
1
vote
2 answers

How to properly build a SELECT query on many fields from two joined tables using their aliases in a dot notation manner with psycopg2

Is there a way to convert these identifiers to a PostgreSQL query using psycopg2: total_query_fields = ( 'p.id', 'p.name', 'p.type', 'p.price', 'o.date', # please, notice the 'o' alias here 'o.transaction', # please,…
swiss_knight
  • 5,787
  • 8
  • 50
  • 92
1
vote
1 answer

Convert Unknown ESPG to ESPG 4326

In running a spatial query in postgres, I got the following error: psycopg2.errors.InternalError_: lwgeom_intersection: GEOS Error: TopologyException: Input geom 1 is invalid: Self-intersection at or near point 676597.26377722982 3673373.5709498846…
CNIDog
  • 374
  • 3
  • 18
1
vote
2 answers

postgres delete query for batch using python

I want to do the bulk delete in postgres using python and my where clause has multiple columns to fetch the correct record. Ex: For One records i ran this delete products where company_id='123' and product_id=1; I tried this for multiple records but…
Raju
  • 249
  • 1
  • 3
  • 13
1
vote
0 answers

Remote Postgresql Query - Permission denied for table xxxx

Struggling to remotly query a postgres database. I've populated the /etc/postgresql/12/main/pg_hba.conf / postgresql.conf with the correct information. I know I can query remotely as its working from within PyCharm. But EVERY time I try this…
Lewis Morris
  • 1,916
  • 2
  • 28
  • 39
1
vote
0 answers

Postgres/Python: Executed successfully but no rows inserted

Could somebody pls help me to perform insert operation to postgres database from python? I have a dataframe: df_routes From To A B B A for index, row in df_routes.iterrows(): cursor.execute("insert into table(id, version,…
1
vote
1 answer

Why does Django/Postgres appear to save but doesn't, gives 'connection already closed'?

I'm using Django + Postgres on Windows 10 WSL Ubuntu 18.04.5 LTS. Saving data to postgres seems to work, yet when I access the table using psql on the command line, the data isn't there. Refreshing the webpage (reloading Django) also shows the old…
Ron
  • 357
  • 1
  • 6
  • 18
1
vote
2 answers

exporting data from psql to json formatted wrong

In my flask app I am trying to practice taking data from a psql table and putting it in a dropdown. I am using this to get the data with psycopg2 using a query from here: def load_authors(self): # sql = "SELECT * FROM authors" sql = "select…
Evan
  • 67
  • 4
1
vote
0 answers

psycopg2 is not reading/fetching the exact float value with full decimals from postgresql database

we have a column in the PostgreSQL table, the column type is float(8) and in 1 record we have a value of 21.291400909423828 under that column. When we are reading from python using psycopg2 with a simple SQL query, we are getting the record but the…
Jagadeesh
  • 119
  • 2
  • 7
1
vote
0 answers

Django Apache server error. no module named 'psycopg2._psycopg' [Dulicate, but duplicate answers didn't work :(]

I am running ubuntu-server 20 and I am trying to run django deplyments server on it with apache2 and libapache2-mod-wsgi-py3. I was having many errors but i somehow managed to fix them but I am stuck on this…
NickNaskida
  • 106
  • 7
1
vote
1 answer

AWS lambda (python): Dockerfile to install psycopg2?

I'm trying to use this tutorial to upload a docker container to AWS ECR for Lambda. My problem is that my python script uses psycopg2, and I couldn't figure out how to install psycopg2 inside the Docker image. I know that I need postgres-devel for…
Attila Toth
  • 187
  • 1
  • 2
  • 13
1
vote
4 answers

Creating a method to connect to postgres database in python

I'm working on a python program with functionality such as inserting and retrieving values from a postgres database using psycopg2. The issue is that every time I want to create a query I have to connect to the database so the following code snippet…
NicLovin
  • 317
  • 3
  • 20
1
vote
2 answers

psycopg2.errors.SyntaxError: syntax error at or near

Psycopg2 has been giving me this error whenever I try to update a row: Traceback (most recent call last): File "p:/Projects/Freelance/Optometry_Inventory/code/tester.py", line 39, in new_user.updateUser(*(fname, lname, username, role,…
le_travie
  • 19
  • 2
  • 7
1
vote
0 answers

How can I insert a Pandas dataframe into a PostgreSQL table?

I am new to Python, I am trying to insert large panda dataframe but somehow I am unable to achieve it. I tried several approach but getting different exception. Below is the table structure: create table test (column1 varchar(80),…
KKL
  • 41
  • 2
1
vote
1 answer

psycopg2 - List index out of range for html (large string) field

I have a webcrawler that should save/insert the html page content to a PostgreSQL Database with some other meta data fields. When inserting the html content field using mogrify I'll get the error message List index out of range. If I use a static…
Maeaex1
  • 703
  • 7
  • 36
1 2 3
99
100