Re: how to add 'time with time zone' data types and 'interval' data types - Mailing list pgsql-novice

From Andreas Kretschmer
Subject Re: how to add 'time with time zone' data types and 'interval' data types
Date
Msg-id 20140106193802.GA17113@tux
Whole thread Raw
In response to how to add 'time with time zone' data types and 'interval' data types  (avpro avpro <avprowebeden@gmail.com>)
Responses Re: how to add 'time with time zone' data types and 'interval' data types
List pgsql-novice
avpro avpro <avprowebeden@gmail.com> wrote:

> hi all,
>
> 1st scenario: i have a table with two fields both of them ''time with time
> zone'. How could I add them? i would like to have something like: SELECT
> table.field1 + table.field2 as sum;

Add 2 TIME's? Make no sense.

test=*# select '9:00'::time + '12:00'::time;
ERROR:  operator is not unique: time without time zone + time without
time zone
LINE 1: select '9:00'::time + '12:00'::time;
                            ^
HINT:  Could not choose a best candidate operator. You might need to add
explicit type casts.


What about to add 23:00 and 21:00? 44:00 as TIME?


> 2nd scenario, similar but this time data types are 'interval': i have a table
> with two fields both of them ''interval'. How could I add them? i would like to
> have something like: SELECT table.field1 + table.field2 as sum;

Just do it:

test=*# select '9:00'::interval + '12:00'::interval;
 ?column?
----------
 21:00:00
(1 row)



Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


pgsql-novice by date:

Previous
From: avpro avpro
Date:
Subject: how to add 'time with time zone' data types and 'interval' data types
Next
From: Sergey Konoplev
Date:
Subject: Re: Master-slave failover question