Re: Problem with extract(epoch from interval ...

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
Cc: kaloyan(at)digsys(dot)bg, pgsql-sql(at)postgresql(dot)org
Subject: Re: Problem with extract(epoch from interval ...
Date: 2013-01-23 14:37:09
Message-ID: 50FFF595.2070502@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 01/23/2013 03:00 AM, Ian Lawrence Barwick wrote:
> Hi
>
> 2013/1/23 Kaloyan Iliev <kaloyan(at)digsys(dot)bg>:
>> Hi,
>> I have a little problem with extract epoch from interval. It seems that the
>> query works if the interval is in a string but not from DB field.
>> Could someone provide support.
> (...)
>
> You have a casting error; instead of:
>
>> dbr=# SELECT extract(EPOCH FROM INTERVAL b) FROM a;
>> ERROR: syntax error at or near "b"
>> LINE 1: SELECT extract(EPOCH FROM INTERVAL b) FROM a;
>
> use
>
> SELECT extract(EPOCH FROM b::INTERVAL) FROM a;
>
> or
>
>
> SELECT extract(EPOCH FROM CAST (b AS INTERVAL)) FROM a;

Would it not be simpler:

test=> SELECT extract(epoch from b) from a;
date_part
-----------
2592000
7776000
15552000
(3 rows)

As the b field is already an interval.

>
>
> Regards
>
> Ian Barwick
>
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas 2013-01-24 00:58:25 How to access multicolumn function results?
Previous Message Andreas 2013-01-23 12:11:55 Re: Re: [SQL] need some magic with generate_series()