Search Postgresql Archives

Re: Timestamp with timezone query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not having any luck with this. 
TIME WITH TIME ZONE columns are being handle slightly different for
TIMESTAMP WITH TIME ZONE.

If I have the following data...

          mydate          |    mytime
------------------------------------------------------------------------
--------
 2006-09-26 12:12:08-04 | 12:12:08-04

I tried a different method to query timestamps with a timezone. The
following returns a row.
select mytime from table where mydate = timestamp with time zone
'2006-09-26 16:12:08+00' 

If I do the samething with the time column, I do not get anything back. 
select mytime from table where mytime = mytime with time zone
'16:12:08+00'; 

The purpose of the 'mytime' column was to do searchs on only the time
portion of a timestamp.

Is it maybe possible to search on a timestamp but wildcare the date
part?
As I mentioned, I am getting timestamp and time from a client that is
converted to utc. 

Therefore is it possible to build a query like :

Select * from table where mydate = timestamp with time zone '%
16:12:08+00'  i.e. wildcard the date portion?

 
 
 

________________________________

From: Brandon Aiken [mailto:BAiken@xxxxxxxxxxxxxxx] 
Sent: Tuesday, September 26, 2006 12:47 AM
To: Harry Hehl; pgsql-general@xxxxxxxxxxxxxx
Subject: RE: [GENERAL] Timestamp with timezone query




I'm not at my dev station to check, but what about:
SELECT myTime AT TIME ZONE 'UTC' FROM theTable;

Then try:
SELECT myTime AT TIME ZONE 'UTC' FROM theTable WHERE myTime =
'19:30:00-00';

Or:
SELECT myTime AT TIME ZONE 'UTC' FROM theTable WHERE myTime = TIME WITH
TIME ZONE '19:30:00-00';

If that doesn't work you might try extracting epoch to convert the time
to an integer:
SELECT myDate, myTime FROM theTable where EXTRACT(EPOCH FROM myTime) =
EXTRACT(EPOCH FROM TIME WITH TIME ZONE '19:30:00-00');


Brandon Aiken

-----Original Message-----
From: Harry Hehl [mailto:Harry.Hehl@xxxxxxxxxxxxxx]
Sent: Mon 9/25/2006 9:21 PM
To: Brandon Aiken
Subject: RE: [GENERAL] Timestamp with timezone query

Hi Brandon,

>>postgres=# select time with time zone '00:30:00-05' at time zone
'utc';
This is not quite when I am doing. The time I get is already in UTC.

This is what I have...

date           | timestamp(6) with time zone |
time           | time(6) with time zone      |


select date,time  from test where date = '2000-02-10 19:30:00' at time
zone 'utc';
          date          |    time
------------------------+-------------
 2000-02-11 00:30:00-05 | 00:30:00-05


I get date and time from a remote client in UTC. In the above case
(which works) '2000-02-10 19:30:00' is UTC, so the query returns the
desired result.  I have to do the same thing with time.

So I tried...

select date,time  from test where time  = '19:30:00' at time zone 'utc';
ERROR:  invalid input syntax for type timestamp with time zone:
"19:30:00"


select date,time  from test where time  = time with time zone '19:30:00'
at time zone 'utc';
select date,time  from test where time  = time with time zone
'19:30:00-00' at time zone 'utc';

Both return...
 date | time
------+------
(0 rows)


This get close (I think)
select  cast( ('2000-01-01 19:30:00' at time zone 'utc') as time );
 timezone
----------
 00:30:00

but when used in a table query...

select  date,time from test where time = cast( ('2000-01-01 19:30:00' at
time zone 'utc') as time );
 date | time
------+------
(0 rows)


Any ideas would be much appreciated.

Thanks
Harry





-----Original Message-----
From: Brandon Aiken [mailto:BAiken@xxxxxxxxxxxxxxx]
Sent: Mon 9/25/2006 5:42 PM
To: Harry Hehl
Subject: RE: [GENERAL] Timestamp with timezone query

Hm?  Works for me:

postgres=# select time with time zone '00:30:00-05' at time zone 'utc';
  timezone
-------------
 05:30:00+00
(1 row)

What are you trying to do with the query?

--
Brandon Aiken
CS/IT Systems Engineer

-----Original Message-----
From: pgsql-general-owner@xxxxxxxxxxxxxx
[mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Harry Hehl
Sent: Monday, September 25, 2006 5:34 PM
To: pgsql-general@xxxxxxxxxxxxxx
Subject: Re: [GENERAL] Timestamp with timezone query

Thanks, that does it.
select * from table where column = '2006-02-10 19:30:00' AT TIME ZONE
'utc';

I also have a TIME WITH TIMEZONE column that I have to do the same thing
with but AT TIME ZONE can't be used directly. I tried several approaches
but I either get incorrect results or syntax errors. Is there a way to
do the same thing with TIME columns?

 

-----Original Message-----
From: Brandon Aiken [mailto:BAiken@xxxxxxxxxxxxxxx]
Sent: Monday, September 25, 2006 11:39 AM
To: Harry Hehl; pgsql-general@xxxxxxxxxxxxxx
Subject: RE: [GENERAL] Timestamp with timezone query

Use the AT TIME ZONE construct:

http://www.postgresql.org/docs/8.1/interactive/functions-datetime.html#F
UNCTIONS-DATETIME-ZONECONVERT

--
Brandon Aiken
CS/IT Systems Engineer

-----Original Message-----
From: pgsql-general-owner@xxxxxxxxxxxxxx
[mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Harry Hehl
Sent: Monday, September 25, 2006 11:06 AM
To: pgsql-general@xxxxxxxxxxxxxx
Subject: [GENERAL] Timestamp with timezone query

Hello,

I have a table with TIMESTAMP WITH TIMEZONE column. I would like to
query for a timestamp using a different timezone.

For example if a column contains '2006-02-11 00:30:00-05'
select * from table where column='2006-02-10 19:30:00+00' would return
the column containing '2006-02-11 00:30:00-05'.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux