skip to Main Content

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

Mysql – Slow sqlalchemy ".in_" clause

I'm trying to execute the following query using sqlalchemy: query = session.query( func.count(ExampleTable.id) ).filter(ExampleTable.environment == self.environment)) if ids_list: query = query.filter(ExampleTable.id.in_(ids_list)) I noticed it was slow, so i did a simple timing "benchmark": start = perf_counter() query.first() print(format(perf_counter() - start,…

VIEW QUESTION
Back To Top
Search