Обсуждение: What Am I Doing Wrong?

Поиск
Список
Период
Сортировка

What Am I Doing Wrong?

От
"Lane Van Ingen"
Дата:
I have been trying to subtract two timestamps from each other to determine
the difference between the two timestamps (current time and a past timestamp
called 'updated_time') IN SECONDS, but no luck.

The trouble I am having is getting the first timestamp, representing the
current time, to translate to seconds; have tried different commands (now(),
localtimestamp, current_timestamp, etc)

What am I doing wrong? Sample statement and error message is below:
                     ------------------------------------------

select EXTRACT(EPOCH from TIMESTAMP current_timestamp) - EXTRACT(EPOCH from
TIMESTAMP updated_time) ::integer

ERROR:  syntax error at or near "current_timestamp" at character 37




Re: What Am I Doing Wrong?

От
Michael Fuhr
Дата:
On Tue, Oct 18, 2005 at 03:38:54PM -0400, Lane Van Ingen wrote:
> select EXTRACT(EPOCH from TIMESTAMP current_timestamp) - EXTRACT(EPOCH from
> TIMESTAMP updated_time) ::integer
> 
> ERROR:  syntax error at or near "current_timestamp" at character 37

What are you intending "TIMESTAMP" to do?  If you're trying to do
a cast then see "Type Casts" in the documentation for the correct
syntax:

http://www.postgresql.org/docs/8.0/interactive/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS

You might not need a cast at all:

test=> SELECT extract(epoch FROM current_timestamp);   date_part     
------------------1129678734.81522
(1 row)

-- 
Michael Fuhr