psycopg2

Trying to use Python variable names in psycopg2 queries

Trying to use Python variable names in psycopg2 queries Question: I am writing part of a Python program where I query a PostgreSQL table called stockNames and use the results to print information based on user input. stockNames has the following layout: company stockTicker industry Starbucks SBUX Food/Beverage … I also have a series of …

Total answers: 1

Trying to convert psycopg2 -> Python data from list tuples to dict

Trying to convert psycopg2 -> Python data from list tuples to dict Question: I have a postgreSQL table called stockdata with financial statement information for about 250 companies with the following setup: Company q4_2022_revenue q3_2022_revenue CPI Card 126436000 124577000 Zuora 103041000 101072000 … I used the psycopg2 package in Python to import this data into …

Total answers: 2

How to omit certain parts of a SQL query

How to omit certain parts of a SQL query Question: Disclaimer that I’m highly aware there’s a better way to word the question, if someone wants to suggest a better way I’d be happy to change it I’ve been working with DynamoDB for the past 4 years and now I’m switching one of my tables …

Total answers: 1

Real time notifications from a Postgres function

Real time notifications from a Postgres function Question: I am trying to execute a function in Postgres which contains a number of Raise statements for debugging and info. While I am able to connect to DB and get raise statements using conn.notices(). These are not printed to python console on a real time basis and …

Total answers: 1

copy temp from stdin with skip id

copy temp from stdin with skip id Question: I have a huge file with some data and need to insert it into the crm database. I have tested it with pandas.to_sql, but I also need to check for duplications and update data in duplications case, so I decided to use this: SQL_STATEMENT = """ CREATE …

Total answers: 1

Error when applying a timeframe mask to dataframe

Error when applying a timeframe mask to dataframe Question: Intro I am writing a piece of python code that uses pcycopg2, pandas and datetime that retrieves information from a PGAdmin database, which filters the data to the last 14 days of activity. The columns I am pulling from the database are: id (Unique Number), createdby …

Total answers: 1

Psycopg2 – Error during insert due to double quotes

Psycopg2 – Error during insert due to double quotes Question: I am using Python + Psycopg2 to insert an array of texts. elems column is of type text[]. a = ["A ”B” C"] cursor.execute(f""" INSERT INTO table(elems) VALUES (ARRAY{a}::text[]) """) Error: column "A ”B” C" does not exist The error above is due to the …

Total answers: 1

How to update postgres array on Python

How to update postgres array on Python Question: I selected column "user_list" in ‘users’ table and fetched to a python variable called "u_list". I appended ‘item’ in it and tried to update "user_list", but got a lot of errors. I tried searching on stackoverflow, but nothing helped. code: cursor.execute(f’SELECT user_list FROM users WHERE id=442392434899681280′) u_list …

Total answers: 1