Skip to content
Advertisement

How to use Peewee to make CASE SQL queries?

I have a table in postgres that holds a priority integer for each row. The priority needs to update whenever I add a new row or change the priority of an existing one for all of the other rows in the table.

One way to do it in pure SQL would be with a CASE query:

Question: How can I use the peewee ORM in python to facilitate this query?

I couldn’t find a way to do it in the documentation. Although the documentation offers some great examples, my use case doesn’t fit any one of the examples.

Advertisement

Answer

You can use peewee.Case (docs: http://docs.peewee-orm.com/en/latest/peewee/api.html#Case ). It is well documented.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement