Re: how to add 'time with time zone' data types and 'interval' data types

From: avpro avpro <avprowebeden(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: how to add 'time with time zone' data types and 'interval' data types
Date: 2014-01-07 15:28:06
Message-ID: CAAQdDn=RbzwMRCd5vNVFdLBqA85+i-EUBu=1vKDzF7tHy+k_Uw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

i tried select '12:00'::interval + '9:00'::interval; and worked.

but, my fields are time with time zone, because the user needs to introduce
the info in this format.

in this case, which is the correct syntax to find out how long the travel
last between two entries, f1 and f2?

select '12:00'::time - '9:00'::time; didn't work.

Johny

On 6 January 2014 20:38, Andreas Kretschmer <akretschmer(at)spamfence(dot)net>wrote:

> avpro avpro <avprowebeden(at)gmail(dot)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°
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Binand Sethumadhavan 2014-01-07 15:57:26 Re: how to add 'time with time zone' data types and 'interval' data types
Previous Message Sameer Kumar 2014-01-07 08:39:32 Re: Testing if a Column Exists in a NEW record of a Trigger Function