skip to Main Content

Update if property already exists on bulk import with SQLAlchemy and PostgreSQL

I have a table with primary uuid key, unique article and some other params. My model: class Product(Base): __tablename__ = "products" idf: Mapped[str] = mapped_column(primary_key=True, unique=True) name: Mapped[str] = mapped_column(nullable=False) article: Mapped[str] = mapped_column(nullable=False, unique=True) category: Mapped[str] = mapped_column(default="") description:…

VIEW QUESTION

How to check if key is in JSON sqlachemy

I am trying to select a segment if: settings dict is not null Has key user_parameters in it And user_parameters (dict) has key user_id in it Code below: user_id = '100952' select([self.db.segments]).where( and_( self.db.segments.c.settings.isnot(None), cast(self.db.segments.c.settings, JSON)["user_parameters"].as_string().contains(f"'{user_id}'"), ) ) Converting JSON…

VIEW QUESTION
Back To Top
Search