1

I'm trying to add 2 'time without timezone' columns in postgres. What is the best way to achieve or correct this?

SELECT time_of_day + offset_time
FROM event_time;

"Error: operator is not unique: time without time zone + time without time zone. HINT: Could not choose a best candidate operator. You might need to add explicit type casts. SQL state: 42725".

3
  • 5
    You don't. You add an interval to a timestamp. Commented May 7, 2021 at 17:04
  • A time is a "point in time". Adding "8 in the morning" to "10 in the evening" doesn't really make sense. Commented May 7, 2021 at 18:58
  • In other words: change the data type of offset_time to interval. Commented May 8, 2021 at 3:38

1 Answer 1

3

What is happening:

select '11:34'::time + '1:00'::time;
ERROR:  operator is not unique: time without time zone + time without time zone
LINE 1: select '11:34'::time + '1:00'::time;

Per Gordon Linoffs comment, what you need to do:

select '11:34'::time + '1:00'::interval;
 ?column? 
----------
 12:34:00

Per docs Date/Time Operators you can subtract times, but you can't add them. You can only add an interval to a time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.