views:

13

answers:

1

Hi all,

I have a pgsql database , i want to compare two fields with there timestamp values.

basic query

select t1.valu1, t1.value2 from table1 as t1 where t1.valu1 == t1.valu2

With TimeStamp comparison

select t1.valu1, t1.value2 from table1 as t1 where EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE  t1.valu1 ) ==  EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE  t1.valu2 ) 

the sample values of valu1 is "14:50:15", "10:50:15" and valu2 "11:10:15", "17:50:15"

I want to convert the valu1 and valu2 to timestamps and after that compare two timestamps

// syntax of extract
EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '20:38:18');

I Got Error in the following format

EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE  t1.valu2 ) 
A: 

You have to give, at least, a day, e.g.:

select EXTRACT(EPOCH FROM '2010-07-05 20:38:18'::timestamptz);

gives

 date_part
------------
 1278358698
Artefacto
but in the pgsql site i had seen the syntax which i used, but in the example its given in a quotes and mine is a field value. So I think the error is there? But i dont know how to convert
coderex
and i need to use in where clause
coderex
@cod As to the first comment, be more clear; as to the second, it's exactly the same in the where clause. But the real question is – why do you want to compare the epochs? Why not the timestamptz values themselves?
Artefacto
sorry!! these are the string values..
coderex
OK, if your times are just strings like hour:minute:seconds, why don't you compare the string themselves?
Artefacto