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

From: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
To: kaloyan(at)digsys(dot)bg
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Problem with extract(epoch from interval ...
Date: 2013-01-23 11:00:39
Message-ID: CAB8KJ=iKs9A4WHXkUt1PEuuxcj4ajBFr19VR2Ce56wJbKOs2Jw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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;

Regards

Ian Barwick

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kaloyan Iliev 2013-01-23 11:23:22 Re: Problem with extract(epoch from interval ...
Previous Message Kaloyan Iliev 2013-01-23 10:54:56 Problem with extract(epoch from interval ...