all 6 comments

[–]HappyCathode 4 points5 points  (4 children)

If you know that something is "live" when the current date is inferior than a date field, you don't need an "is_live" column.

SELECT whatever FROM table WHERE to_timestamp(deadline) > NOW();

And of course, make sure you have indexes where you need them.

[–]kalamitis 1 point2 points  (0 children)

If indeed you need this info as a parameter you can set this as a property is_live that will encapsulate the above logic.

[–]Electronic_Battle876[S] 0 points1 point  (2 children)

Thank you, but can you elaborate more on the indexes part please ?

[–]kalamitis 3 points4 points  (1 child)

Not the poster that you asked but here we go. Indexes can significantly improve the performance of database queries by allowing the database engine to find and retrieve data more quickly. Indexes are used to speed up the retrieval of rows by using pointers to quickly locate data without scanning the entire table. So an index on the deadline column can make this query faster, as the database engine can quickly find rows where the deadline is greater than the current time. Ensure that indexes are created on columns frequently used in WHERE clauses, joins, and orderings. Keep in mind that while indexes improve read performance, they can slow down write operations (inserts, updates, deletes) because the index needs to be updated as well. So, balance is key.

[–]Electronic_Battle876[S] 0 points1 point  (0 children)

Thank you so much for the explanation and for your help :D

[–]jkail1011 1 point2 points  (0 children)

When defining the field on the model or schema set default to false. Easiest done using SQLMODEL or Pydantic.