skip to Main Content

I have this in the where clause of my SQL query:

‘2023/10/21 14:46:32.805068000’ + interval ‘1 second’

This causes me to have an "invalid input syntax for type interval" error.

Does anyone have a suggestion?

2

Answers


  1. You have to tell PostgreSQL that the first string is a timestamp

    timestamp '2023/10/21 14:46:32.805068000' + interval '1 second'
    

    If you don’t PostgreSQL tries to guess, and assumes you are adding 2 values with the same type (2 intervals).

    Login or Signup to reply.
  2. You need to have a timestamp datatype to calculate .

    SELECT '2023/10/21 14:46:32.805068000'::timestamp + interval '1 second'
    
    ?column?
    2023-10-21 14:46:33.805068
    SELECT 1
    

    fiddle

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