ash
ash

Reputation: 11

postgres: how to add 2 'time without timezone' columns?

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".

Upvotes: 1

Views: 1096

Answers (1)

Adrian Klaver
Adrian Klaver

Reputation: 19570

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.

Upvotes: 3

Related Questions