Skip to content
Advertisement

PostgreSQL NOT operator in SQLAlchemy

I’d like to achieve toggling a boolean flag with just one query.

My query looks as follows:

JavaScript

Does SQLAlchemy supports PostgreSQL NOT (https://www.postgresql.org/docs/current/functions-logical.html) operator. How this can be achieved different way?

Advertisement

Answer

As Adrian Klaver points out in their comment, SQLAlchemy’s not_ operator will toggle the values. All of these statements are equivalent:

JavaScript

Will generate this SQL:

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