Roman Prykhodchenko
Roman Prykhodchenko

Reputation: 13325

Can I use lambda to create a query in SQLAlchemy?

I need to implement a function that takes a lambda as the argument and queries the database. I use SQLAlchemy for ORM. Is there a way to pass the lambda, that my function receives, to SQLAlchemy to create a query?

Sincerely, Roman Prykhodchenko

Upvotes: 2

Views: 2124

Answers (1)

Jochen Ritzel
Jochen Ritzel

Reputation: 107746

I guess you want to filter the data with the lambda, like a WHERE clause? Well, no, functions nor lambdas cannot be turned into a SQL query. Sure, you could just fetch all the data and filter it in Python, but that completely defeats the purpose of the database.

You'll need to recreate the logic you put into the lambda with SQLAlchemy.

Upvotes: 2

Related Questions