Search code examples
sqlcastingdb2query-optimizationsql-timestamp

Rows with a timestamp value yesterday in DB2


How do I select rows with a timestamp value at any time yesterday? The DBMS is DB2.

SELECT *
  FROM my_table
 WHERE CAST (my_timestamp_col AS DATE) = CURRENT DATE - 1 DAY

This is what I currently have but is casting timestamps as date inefficient? Can it make use of indexes?


Solution

  • I would instead recommend:

    where my_timestamp_col >= current date - 1 day and
          my_timestamp_col < current date