skip to Main Content

I want to write this type query :

SELECT 
  CASE 
      WHEN t1.date_closed - t1.created_date < t3.estimated_solution_time_minutes  THEN 'не в SL'
  ELSE 'в SL'
  END AS  result

but t1.date_closed and t1.created_date are intervals like this ‘2023-05-02 11:30’,
but t3.estimated_solution_time_minutes is integer and i get error: ERROR: operator does not exist: interval < integer

how can i cast these intervals to integer

2

Answers


  1. Yu can use this syntax for changing types

    t1.date_closed :: INT
    t1.created_date :: INT
    

    the second way is

    CAST(t1.date_closed as INT)
    CAST(t1.created_date as INT)
    
    Login or Signup to reply.
  2. The problem is not the CAST. In this case, you probably want EXTRACT(SECONDS FROM (date_closed - created_date))

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search