Re: Problem with extract(epoch from interval ... - Mailing list pgsql-sql

From Ian Lawrence Barwick
Subject Re: Problem with extract(epoch from interval ...
Date
Msg-id CAB8KJ=iKs9A4WHXkUt1PEuuxcj4ajBFr19VR2Ce56wJbKOs2Jw@mail.gmail.com
Whole thread Raw
In response to Problem with extract(epoch from interval ...  (Kaloyan Iliev <kaloyan@digsys.bg>)
Responses Re: Problem with extract(epoch from interval ...
Re: Problem with extract(epoch from interval ...
List pgsql-sql
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;


Regards

Ian Barwick



pgsql-sql by date:

Previous
From: Kaloyan Iliev
Date:
Subject: Problem with extract(epoch from interval ...
Next
From: Kaloyan Iliev
Date:
Subject: Re: Problem with extract(epoch from interval ...