postgresql

How to detect changes in custom types in sqlalchemy

How to detect changes in custom types in sqlalchemy Question: I am working on custom types in sqlalchemy columns using TypeDecorator. I’m storing my data in JSONB inside Postgres DB, but in code I am serializing and deserializing it in a data class. But when I change any field of that data class, it didn’t …

Total answers: 2

Connect CloudSQL Postgres Db using Python

Connect CloudSQL Postgres Db using Python Question: So I am DevOps engineer please excuse for my lack of knowledge in python development. I am trying to connect a CloudSQL Postgres 14 Db using Python. So that I can insert data and read data from my application. Can someone help me understand why I am getting …

Total answers: 2

psycopg3 inserting dict into JSONB field

psycopg3 inserting dict into JSONB field Question: I have a table with a JSONB field and would like to insert into it using a named dict like so: sql = "INSERT INTO tbl (id, json_fld) VALUES (%(id)s, %(json_fld)s)" conn.execute(sql, {‘id’:1, ‘json_fld’: {‘a’:1,’b’:false, ‘c’: ‘yes’}}); I tried the answers in this question but those all apply …

Total answers: 2

Indexing a SearchVector vs Having a SearchVectorField in Django. When should I use which?

Indexing a SearchVector vs Having a SearchVectorField in Django. When should I use which? Question: Clearly I have some misunderstandings about the topic. I would appreciate if you correct my mistakes. So as explained in PostgreSQL documentation, We need to do Full-Text Searching instead of using simple textual search operators. Suppose I have a blog …

Total answers: 3

I created a table and I'm trying to modify it but I get this error

I created a table and I'm trying to modify it but I get this error Question: I started tody with Python SQL Database conexion (or in general python databse collection i guess) and I was following a tutorial on youtube about how to create and modify the table, but at the moment when I tried …

Total answers: 1

How to delete rows by a condition using sqlalmchemy and fastapi?

How to delete rows by a condition using sqlalmchemy and fastapi? Question: I’m trying to delete some rows that a ‘null’ in a Postgresql db by this: async def delete_empty_batches(): query = Batches.delete().where(Batches.c.acquired_by_warehouse_date is None) database.execute(query).fetchall() s = Batches.select() return await database.execute(s).fetchall() But nothing happens. I have tried to make a query in pgAdmin and …

Total answers: 2

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

Get last actual data

Get last actual data Question: There is a table rule_chains: ID payroll_type_id stuff_department_id start_date 1 1 89 2023-03-01 2 2 89 2023-03-01 3 1 89 2023-04-01 My problem is to get the actual entity for today. For example today is 2023-03-01 and I need to get this two entity with id = 1 and id …

Total answers: 1

How do I connect my telegram bot (telebot) to PostgreSQL url

How do I connect my telegram bot (telebot) to PostgreSQL url Question: I would like to learn how to connect my telegram bot to database url so that I store bot users, date of join and user information. Help me through that tutorial. How to connect a my telegram bot to PostgreSQL/database url. #code from …

Total answers: 1

How to assign the url of the uploaded photo from AWS to database(postgresql) model in the same endpoint

How to assign the url of the uploaded photo from AWS to database(postgresql) model in the same endpoint Question: Below that there is an endpoint that uploads a photo to aws-s3 and return the url of the photo. This works well. session1 = boto3.Session( aws_access_key_id=’XXXXXXXXXX’, aws_secret_access_key=’XXXXXXXXX’ ) S3_BUCKET_NAME = "XXXXX" s3 = session1.resource("s3") bucket = …

Total answers: 2