472,373 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

SET TIME ZONE with GMT+X notation

I'm a bit confused about SET TIME ZONE and its effect on PostgreSQL's
date processing.

In my experience with timestamps in all other *nix-based software
systems, a timestamp is always a numeric representation of the
time elapsed since the epoch, in GMT. Thus, a function that
returns the current timestamp should always return the same value,
regardless of timezone. The display of that value may change based
on the system's timezone, but the value stored does not vary based
on current timezone settings.

For the most part, I've seen the same from PostgreSQL. But I'm
seeing some strange behavior when I use the "GMT+X" format for
timezone specifications.

Here's a simple table:

foo=> \d bar
Table "bar"
Column | Type | Modifiers
------------+--------------------------+-------------------------------------------
timestamp1 | timestamp with time zone | not null default timeofday()
timestamp2 | timestamp with time zone | not null default
"timestamp"('now'::text)
media_type | character varying(50) | not null default 'IMAGE'
Note that it uses timeofday() for the default for one timestamp and
"now" for the default for the other (we've been experimenting with the
differences between the two, as we've seen some serious drift in the
values returned by "now" -- but that's another story).

So we insert a record, set the time zone to "GMT+4" (which corresponds
to the current offset for EDT), then insert another record:

foo=> insert into bar (media_type) values ('baz'); set time zone
'GMT+4'; insert into bar (media_type) values ('baz');
INSERT 469438 1
SET VARIABLE
INSERT 469439 1

Now look at the time values inserted:

foo=> select date_part('epoch',timestamp1),
date_part('epoch',timestamp2) from bar;
date_part | date_part
------------------+------------------
1060783749.77958 | 1060783749.77807
1060769349.78216 | 1060783749.78164

Note that in the first column (the one that uses timeofday() for
its default values), there is a four-hour difference between
the values, even though the inserts were performed about 3ms
apart! The column that uses 'now' for its default values does not
exhibit this difference.

Now repeat the experiment using "America/New_York" instead of
'GMT+4', and the effect goes away:

foo=> insert into bar (media_type) values ('baz'); set time zone
'America/New_York'; insert into bar (media_type) values ('baz');
INSERT 469442 1
SET VARIABLE
INSERT 469443 1
foo=> select date_part('epoch',timestamp1),
date_part('epoch',timestamp2) from bar;
date_part | date_part
------------------+------------------
1060783843.09787 | 1060783843.0957
1060783843.10056 | 1060783843.09996
(2 rows)
I apologize for the long post. But I didn't see a clearer way to
communicate this problem. I'm seeing this with PostgreSQL 7.2.3
on RH Linux 7.3. I know it's not the most current version, but
I've checked the HISTORY files to make sure there hasn't been a
fix to this problem. I saw a few timezone changes, but I don't
think this problem was addressed.

The reason this is a fairly large problem for me is that I need to
be able to use the 'GMT+X' notatation using PostgreSQL under Cygwin.
It seems that this is the only notation accepted by the cygwin port
of PostgreSQL.

Thanks for any insight.

Jason Priebe
ja**********@yahoo.com
Nov 11 '05 #1
2 6671
ja**********@yahoo.com (Jason Priebe) writes:
Note that it uses timeofday() for the default for one timestamp and
"now" for the default for the other (we've been experimenting with the
differences between the two, as we've seen some serious drift in the
values returned by "now" -- but that's another story).


Uh, have you read
http://www.postgresql.org/docs/view....TETIME-CURRENT

particularly the point about

It is important to realize that CURRENT_TIMESTAMP and related functions
return the start time of the current transaction; their values do not
change during the transaction. timeofday() returns the wall clock time
and does advance during transactions.
regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #2

--- Tom Lane <tg*@sss.pgh.pa.us> wrote:
ja**********@yahoo.com (Jason Priebe) writes:
Note that it uses timeofday() for the default for one timestamp and
"now" for the default for the other (we've been

experimenting with the
differences between the two, as we've seen some

serious drift in the
values returned by "now" -- but that's another

story).

Uh, have you read

http://www.postgresql.org/docs/view....TETIME-CURRENT
particularly the point about

It is important to realize that CURRENT_TIMESTAMP
and related functions
return the start time of the current transaction;
their values do not
change during the transaction. timeofday() returns
the wall clock time
and does advance during transactions.


Yep. I understand that. We're having some issues
with our application where gradually the values from
CURRENT_TIMESTAMP fall further and further behind.
As far as we know, we don't have any transactions
open. We are, however, using PHP's pg_pconnect()
function to connect to the database. The only thing
I can think of is that perhaps a transaction is left
hanging (perhaps due to abnormal termination of a
process), and then another process picks up that
pooled connection and "inherits" the open transaction?
It doesn't make a lot of sense, but it's the only
thing I can think of.

-Jason Priebe
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian | last post by:
I have 4 sites sharing an account on a server that is in the US Eastern time zone. 3 of those sites are for businesses/persons who live in the same time zone, but one is for a restaurant in the US...
8
by: Monty | last post by:
Let's say you provide an online service from 7:00AM to 6:00PM Eastern Time (daylight time in the summer). Is there way of showing these hours of availability on a web page in the user's local...
0
by: Jason Priebe | last post by:
I posted earlier with a very complex example. This simple one gets to the point much faster. timeofday() seems to behave inconsistently when the timezone is set with "GMT+X" notation. foo=>...
2
by: Daniel Jung | last post by:
Hi 1088553069 => Wed Jun 30 01:51:22 2004 CEST I can do the time INT string substitution, but I want a set of "country codes", in order for my users to be able to pick their own preferences....
17
by: Franc Zabkar | last post by:
My D-Link DSL-302G modem/router has a real-time clock whose settings are volatile. To avoid hand keying the date/time via the modem's JS interface, I wonder if there is a way to copy the JS code to...
3
by: deepeshn | last post by:
Hi people, I have a function which will receive 2 parameters:the date field in GMT time and the user's time zone. I have to return a datetime field in the user's time. the thing is the server...
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
1
by: =?Utf-8?B?UmljYXJkbyBRdWludGFuaWxsYQ==?= | last post by:
how to simulate a different time zone? ¿is it possible by code to simulate that i am in a different time zone just for to execute a few lines of code? in my case i am in the time zone...
1
by: nigelesquire | last post by:
I am in need of your assistance. I have a page with multiple unixtime stamps and I need to display them in readable time and date with the user's time zone. Below is the code. <!DOCTYPE...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.