I have two columns in PostgreSQL that store time values (H:M:S) and I use SQLAlchemy.
How can I make a select using SQLAlchemy for values that are not between the two values?
Example 1:
- current time in the interrogation = 10:00:01
- start_time = 16:00:12
- end_time = 22:00:00
Return the value because is outside of this time interval
2:
- current time = 10:00:01
- start_time = 07:00:12
- end_time = 22:00:00
Return nothing because is within this interval.
2
Answers
Use the negation operator NOT with BETWEEN.
To select from the table you would want something like:
As to SQLAlchemy see Between:
and I believe to negate that it would be something like:
select(users_table).where(~between(users_table.c.id, 5, 7))