cratedb

How to subtract days to a Timestamp in CrateDB SQL query?


How can i subtract days to a timestamp in CrateDB SQL query?

Exist something similar to this?

TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 14 DAY)

Solution

  • You can subtract INTERVAL from TIMESTAMP, but before any matematichal operation you need to CAST the datatype, you can do it in this way:

    SELECT now() - CAST('14 day' AS INTERVAL)
    

    Or the same function of above, but in a contracted way

    SELECT now() - '14 day'::INTERVAL;
    

    As a string to be CAST to an INTERVAL you can use a number followed by any of this: