Home > Enterprise >  How to work with time interval in postgreSQL
How to work with time interval in postgreSQL

Time:10-07

I have a postgreSQL query that returns 'Late' when the given condition is met, currently, When i run below query I'm getting an error

SELECT
CASE WHEN CAST(so.scheduled_delivery_time AS date) < CURRENT_DATE OR CAST(so.scheduled_delivery_time AS date) = CURRENT_DATE AND DATETIME(so.scheduled_delivery_time) < DATETIME_SUB(datetime(current_datetime()),  INTERVAL '3' HOUR) THEN 'Late'
END AS status
FROM 
table1

Error

ERROR: function datetime(timestamp without time zone) does not exist Hint: No function matches the given name and argument types.

What I'm I missing?

CodePudding user response:

Hey there — the simplest answer is that there is no function named DATETIME. Also it looks like your values are already timestamps, so you can probably just do this:

so.scheduled_delivery_time < current_datetime() - INTERVAL '3' HOUR

CodePudding user response:

A good starting point to find the available functions, is the fine manual. CURRENT_TIMESTAMP will give you the current timestamp and you can use it like this:

SELECT CURRENT_TIMESTAMP;
  • Related