pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@gmail.com>
To: Ian Lawrence Barwick <barwick@gmail.com>
Cc: kaloyan@digsys.bg
Cc: pgsql-sql@postgresql.org
Subject: Re: Problem with extract(epoch from interval ...
Date: Wed, 23 Jan 2013 06:37:09 -0800
Message-ID: <50FFF595.2070502@gmail.com> (raw)
In-Reply-To: <CAB8KJ=iKs9A4WHXkUt1PEuuxcj4ajBFr19VR2Ce56wJbKOs2Jw@mail.gmail.com>
References: <50FFC180.80507@digsys.bg>
	<CAB8KJ=iKs9A4WHXkUt1PEuuxcj4ajBFr19VR2Ce56wJbKOs2Jw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

On 01/23/2013 03:00 AM, Ian Lawrence Barwick wrote:
> Hi
>
> 2013/1/23 Kaloyan Iliev <kaloyan@digsys.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.klaver@gmail.com


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (4+ messages)

Message-ID: <50FFF595.2070502@gmail.com>
Permalink:  ../50FFF595.2070502@gmail.com/
Also on:    postgresql.org/message-id/50FFF595.2070502@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: adrian.klaver@gmail.com, barwick@gmail.com, kaloyan@digsys.bg
  Subject: Re: Problem with extract(epoch from interval ...
  In-Reply-To: <50FFF595.2070502@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox