timestamp with time zone a la sql99

Started by Dennis Bjorklundover 21 years ago35 messageshackers
Jump to latest
#1Dennis Bjorklund
db@zigo.dhs.org

I've made a partial implementation of a datatype "timestamp with time
zone" as described in the sql standard. The current type "timestamptz"
does not store the time zone as a standard one should do. So I've made a
new type I've called timestampstdtz that does store the time zone as the
standard demands.

Let me show a bit of what currently works in my implementation:

dennis=# CREATE TABLE foo (
a timestampstdtz,

primary key (a)
);
dennis=# INSERT INTO foo VALUES ('1993-02-04 13:00 UTC');
dennis=# INSERT INTO foo VALUES ('1999-06-01 14:00 CET');
dennis=# INSERT INTO foo VALUES ('2003-08-21 15:00 PST');

dennis=# SELECT a FROM foo;
a
------------------------
1993-02-04 13:00:00+00
1999-06-01 14:00:00+01
2003-08-21 15:00:00-08

dennis=# SELECT a AT TIME ZONE 'CET' FROM foo;
timezone
------------------------
1993-02-04 14:00:00+01
1999-06-01 14:00:00+01
2003-08-22 00:00:00+01

My plan is to make a GUC variable so that one can tell PG that constructs
like "timestamp with time zone" will map to timestampstdtz instead of
timestamptz (some old databases might need the old so unless we want to
break old code this is the easiest solution I can find).

I've made an implicit cast from timestampstdtz to timestamptz that just
forgets about the time zone. In the other direction I've made an
assignment cast that make a timestamp with time zone 0 (that's what a
timestamptz is anyway). Would it be possible to make it implicit in both
directions? I currently don't think that you want that, but is it
possible?

With the implicit cast in place I assume it would be safe to change
functions like now() to return a timestampstdtz? I've not tried yet but I
will. As far as I can tell the cast would make old code that use now() to
still work as before.

Any comments before I invest more time into this subject?

--
/Dennis Bj�rklund

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Bjorklund (#1)
Re: timestamp with time zone a la sql99

Dennis Bjorklund <db@zigo.dhs.org> writes:

I've made a partial implementation of a datatype "timestamp with time
zone" as described in the sql standard. The current type "timestamptz"
does not store the time zone as a standard one should do.

I'm aware that there are aspects of the spec behavior that appear to
require that, but is it really an improvement over the implementation
we have?  This is an area in which the standard is pretty brain-dead
--- the entire concept of a "time with time zone" datatype is rather
suspect, for instance.

In particular, I wonder how you will handle daylight-savings issues.
The spec definition seems to preclude doing anything intelligent with
DST, as they equate a timezone with a fixed offset from UTC. That's
not how it works in (large parts of) the real world.

regards, tom lane

#3Dennis Bjorklund
db@zigo.dhs.org
In reply to: Tom Lane (#2)
Re: timestamp with time zone a la sql99

On Thu, 21 Oct 2004, Tom Lane wrote:

I've made a partial implementation of a datatype "timestamp with time
zone" as described in the sql standard. The current type "timestamptz"
does not store the time zone as a standard one should do.

I'm aware that there are aspects of the spec behavior that appear to
require that, but is it really an improvement over the implementation
we have?

Improvement and improvement. The actual time value is of course the same
(the utc part of a timestamp) and the only thing extra you get is that the
time zone is stored. The extra information you do have now, when stored in
this way, is that you store both a utc time and a local time. Will any
application ever need that? Who knows? I think it makes sense and is an
easier model to think about then what pg uses today. So I would use it
even if it means using 2 bytes more storage then what timestamptz do

Just that it is standard also makes it useful. The more things of the
standard we support the easier it is to move between databases. This is
important to me.

I also want to make a general statement that I think that whenever we use
standard syntax we should give it a standard semantics. I don't mind
extensions at all, but as much as we can we should make sure that they
don't clash with standard syntax and semantics.

This is an area in which the standard is pretty brain-dead
--- the entire concept of a "time with time zone" datatype is rather
suspect, for instance.

I havn't look that much at "time with time zone" yet, just timestamps.

I can't see why time with time zone should not also be supported. I can't
really imagine it being used without a date, but if someone wants to store
timestamps as a date+time with time zone, then why not. It would be extra
work tu is it instead of a timestamp (especially for cases where the time
wraps over to the prev/next day), but hey.

In particular, I wonder how you will handle daylight-savings issues.
The spec definition seems to preclude doing anything intelligent with
DST, as they equate a timezone with a fixed offset from UTC. That's
not how it works in (large parts of) the real world.

The tz in the standard is a offset from utc, yes. So when you store a
value you tell it what offset you use. If you are using daylight-savings
time it might be +02 and if not dst it might be +01. What else would you
want to do with it? It's not like you can do anything else with it in pg
as of today, can you?

The stored tz does not say what region of the globe you are in, it says
the distance away from utc in minutes that you are. I could imagine
another datatype that stores the time zone as name, but that's not what
timestamp with time zone does.

--
/Dennis Bj�rklund

#4Robert Treat
xzilla@users.sourceforge.net
In reply to: Dennis Bjorklund (#3)
Re: timestamp with time zone a la sql99

On Thursday 21 October 2004 11:01, Dennis Bjorklund wrote:

On Thu, 21 Oct 2004, Tom Lane wrote:

I'm aware that there are aspects of the spec behavior that appear to
require that, but is it really an improvement over the implementation
we have?

Improvement and improvement. The actual time value is of course the same
(the utc part of a timestamp) and the only thing extra you get is that the
time zone is stored. The extra information you do have now, when stored in
this way, is that you store both a utc time and a local time. Will any
application ever need that? Who knows? I think it makes sense and is an
easier model to think about then what pg uses today. So I would use it
even if it means using 2 bytes more storage then what timestamptz do

In a fit of early morning, pre-coffee thoughts, I'm thinking this might be
just what I've been looking for. In one of my apps we take calls from around
the country for customers and store the time that call came in. Unfortunately
we need to know things like how many calls did we take in an hour across
customers, but also how many calls did we take at 6AM local time to the
customer. The way PostgreSQL works now, you have to store some extra bits
of info in another column and then reassemble it to be able to determine
those two queries, but it sounds like your timestampstdtz would allow that
information to be stored together, as it should be.

--
Robert Treat
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Treat (#4)
Re: timestamp with time zone a la sql99

Robert Treat <xzilla@users.sourceforge.net> writes:

In a fit of early morning, pre-coffee thoughts, I'm thinking this might be
just what I've been looking for. In one of my apps we take calls from around
the country for customers and store the time that call came in. Unfortunately
we need to know things like how many calls did we take in an hour across
customers, but also how many calls did we take at 6AM local time to the
customer. The way PostgreSQL works now, you have to store some extra bits
of info in another column and then reassemble it to be able to determine
those two queries, but it sounds like your timestampstdtz would allow that
information to be stored together, as it should be.

As far as I can tell, Dennis is planning slavish adherence to the spec,
which will mean that the datatype is unable to cope effectively with
daylight-savings issues. So I'm unconvinced that it will be very
helpful to you for remembering local time in addition to true
(universal) time.

regards, tom lane

#6Dennis Bjorklund
db@zigo.dhs.org
In reply to: Tom Lane (#5)
Re: timestamp with time zone a la sql99

On Fri, 22 Oct 2004, Tom Lane wrote:

As far as I can tell, Dennis is planning slavish adherence to the spec,
which will mean that the datatype is unable to cope effectively with
daylight-savings issues. So I'm unconvinced that it will be very
helpful to you for remembering local time in addition to true
(universal) time.

And exactly what issues is it that you see? The only thing I can think of
is if you have a timestamp and then add an interval to it so we jump past
the daylight saving time change date. Then the new timestamp will keep the
old timezone data of say +01 even though we now have jumped into the
daylight saving period of +02.

If you are just storing actual timestamps then the standard definition
works just fine. If I store '2004-10-22 16:20:04 +02' then that's exactly
what I get back. No problem what so ever. There is no DST problem with
that.

It's possible that I will introduce some daylight saving bit or something
like that, I'm not sure yet and I will not commit to anything until I've
thought it over. I don't think there are that much of a problem as you
claim however. Could you give a concret example where it will be a
problem?

My current thinking is that storing the time zone value as HH:MM is
just fine and you avoid all the problems with political changes of when
the DST is in effect or not.

--
/Dennis Bj�rklund

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Bjorklund (#6)
Re: timestamp with time zone a la sql99

Dennis Bjorklund <db@zigo.dhs.org> writes:

And exactly what issues is it that you see? The only thing I can think of
is if you have a timestamp and then add an interval to it so we jump past
the daylight saving time change date. Then the new timestamp will keep the
old timezone data of say +01 even though we now have jumped into the
daylight saving period of +02.

Isn't that sufficient? You can't design a datatype by thinking only of
the data values it stores; you have to think about the operations you
intend to provide as well. A non-DST-capable timestamp datatype is
inherently a few bricks shy of a load. (BTW we really need to fix
the interval type as well...)

At bottom, what I want to be able to do is say
'2004-10-22 10:50:16.916003 America/New_York'
and have the datatype preserve *all* of the information in that. You
are complaining because the existing type only remembers the equivalent
universal time and not the timezone spec. Why should I be satisfied if
it stores only the GMT offset and not the knowledge of which timezone
this really is?

My current thinking is that storing the time zone value as HH:MM is
just fine and you avoid all the problems with political changes of when
the DST is in effect or not.

This is fundamentally misguided. Time zones *are* political whether you
like it or not, and people *do* expect DST-awareness whether you like it
or not. If you still use any computer systems that need to be reset
twice a year because their designers thought DST was not their problem,
don't you roundly curse them every time you have to do it?

If you were planning to store a real (potentially DST-aware) timezone
spec in the data values, I'd be happy. But storing a fixed GMT offset
is going to be a step backwards compared to existing functionality. The
fact that it's sufficient to satisfy the DST-ignorant SQL spec does not
make it a reasonable design for the real world.

One way to do this would be to create a system catalog with entries for
all known timezones, and then represent timestamptz values as universal
time plus an OID from that catalog. There are other ways that small
integer codes could be mapped to timezones of course.

regards, tom lane

#8Bruno Wolff III
bruno@wolff.to
In reply to: Dennis Bjorklund (#6)
Re: timestamp with time zone a la sql99

On Fri, Oct 22, 2004 at 16:28:12 +0200,
Dennis Bjorklund <db@zigo.dhs.org> wrote:

On Fri, 22 Oct 2004, Tom Lane wrote:

As far as I can tell, Dennis is planning slavish adherence to the spec,
which will mean that the datatype is unable to cope effectively with
daylight-savings issues. So I'm unconvinced that it will be very
helpful to you for remembering local time in addition to true
(universal) time.

And exactly what issues is it that you see? The only thing I can think of
is if you have a timestamp and then add an interval to it so we jump past
the daylight saving time change date. Then the new timestamp will keep the
old timezone data of say +01 even though we now have jumped into the
daylight saving period of +02.

I think for just storing values you are fine. When it comes to adding or
subtracting intervals you might get some unexpected results.

#9Dennis Bjorklund
db@zigo.dhs.org
In reply to: Tom Lane (#7)
Re: timestamp with time zone a la sql99

On Fri, 22 Oct 2004, Tom Lane wrote:

At bottom, what I want to be able to do is say
'2004-10-22 10:50:16.916003 America/New_York'

Yes, that's what we said in the last mail and I think there is a value in
having something like this.

universal time and not the timezone spec. Why should I be satisfied if
it stores only the GMT offset and not the knowledge of which timezone
this really is?

You don't need to be satisfied with it. I think a type like the above
would be fine to have. It should however not be called "TIMESTAMP WITH
TIME ZONE" because there is already a definition of that type. We can not
hijack standard types. I would not mind a type like TIMESTAMP WITH TIME
ZONE NAME (or some other name). I could even imagine that I could
implement something like that one day.

My current thinking is that storing the time zone value as HH:MM is
just fine and you avoid all the problems with political changes of when
the DST is in effect or not.

This is fundamentally misguided. Time zones *are* political whether you
like it or not, and people *do* expect DST-awareness whether you like it
or not.

And I never said that time zones are not political, just that HH:MM is a
usable approximation that works fairly well.

But storing a fixed GMT offset is going to be a step backwards compared
to existing functionality.

It's not a step backwards since you can do everything you can do with the
current type plus a little bit more. It's however not a step to the
datatype discussed above.

One way to do this would be to create a system catalog with entries for
all known timezones, and then represent timestamptz values as universal
time plus an OID from that catalog. There are other ways that small
integer codes could be mapped to timezones of course.

This is just fine. You try to make it sound like I am against such a
datatype, I am not. It's however not the datatype that we can expect
applications and other databases to use. So why should we settle for only
that type. Just because you can make a perfect datatype it doesn't mean
that the standard datatype should just be ignored.

What would you store when the user supplies a timestamp like '2004-10-22
17:21:00 +0200'. Should you reject that because you don't know the
time zone name? So your datatype will not work for applications that try
to be compatable with many databases by using the standard?

Maybe one could make a datatype called TIMESTAMP WITH TIME ZONE that can
accept both HH:MM and TimeZoneName. Whenever you store values with HH:MM
time zones you will get the same problem when you add an interval as the
standard type has.

--
/Dennis Bj�rklund

#10Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Bjorklund (#9)
Re: timestamp with time zone a la sql99

Dennis Bjorklund <db@zigo.dhs.org> writes:

You don't need to be satisfied with it. I think a type like the above
would be fine to have. It should however not be called "TIMESTAMP WITH
TIME ZONE" because there is already a definition of that type. We can not
hijack standard types.

Sure we can, as long as they are upward compatible with the standard
behavior. The spec says you can put a numeric-GMT-offset zone in and
get a numeric-GMT-offset zone out. We can do that and also support
named, possibly DST-aware zones. This seems a whole lot better to me
than having two different types (the idea of a GUC variable to choose
which one is selected by a given type name is just horrid).

But storing a fixed GMT offset is going to be a step backwards compared
to existing functionality.

It's not a step backwards since you can do everything you can do with the
current type plus a little bit more.

... except get useful answers from interval addition ...

What would you store when the user supplies a timestamp like '2004-10-22
17:21:00 +0200'. Should you reject that because you don't know the
time zone name?

You are attacking a straw man.

We have put a great deal of work into 8.0 to add the ability to support
real-world zones fully. We did not import src/timezone because we
needed it to implement the SQL spec; we did so because we needed it to
implement what real users want. We are not fully there yet (can't do AT
TIME ZONE conversions with all zones yet, for instance) but I am hoping
to be there by 8.1. It would be folly to invent a timestamp with time
zone type that is going in the other direction while we are trying to
bring the rest of the system up to full speed by allowing all timezone
kinds everywhere.

regards, tom lane

#11Dennis Bjorklund
db@zigo.dhs.org
In reply to: Tom Lane (#10)
Re: timestamp with time zone a la sql99

On Fri, 22 Oct 2004, Tom Lane wrote:

than having two different types (the idea of a GUC variable to choose
which one is selected by a given type name is just horrid).

That is needed no matter what change you do if you want old programs that
use the current timestamp with time zone to work. Today you don't get back
the same time zone as you insert, programs might depend on that.

We are not fully there yet (can't do AT TIME ZONE conversions with all
zones yet, for instance)

Why is that? When one start with a utc value, performing a AT TIME ZONE
operation doesn't look so complicated.

--
/Dennis Bj�rklund

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Bjorklund (#11)
Re: timestamp with time zone a la sql99

Dennis Bjorklund <db@zigo.dhs.org> writes:

On Fri, 22 Oct 2004, Tom Lane wrote:

than having two different types (the idea of a GUC variable to choose
which one is selected by a given type name is just horrid).

That is needed no matter what change you do if you want old programs that
use the current timestamp with time zone to work. Today you don't get back
the same time zone as you insert, programs might depend on that.

[ shrug... ] We've made much larger changes than that in the name of
standards compliance. In practice I think the majority of apps are
working in contexts where they will get back the same zone as they
inserted, if they inserted a zone explicitly at all, so the risk of
breakage is not that high. Having a GUC variable that changes the
semantics underneath you is *much* riskier, to judge by past experience.

We are not fully there yet (can't do AT TIME ZONE conversions with all
zones yet, for instance)

Why is that?

Because it's not done yet. There's a set of GMT-offset-only zone names
wired into the datetime code (look in the "datetime token table") and
those are what AT TIME ZONE knows how to deal with. We need to unify
that old stuff with the src/timezone code, but we ran out of time to do
it in 8.0.

The way I see it, we have three sorts of zones to deal with: fixed
numeric offsets from UTC, names that represent fixed offsets (eg, "EST"
is the same as UTC-5), and names that represent DST-variable offsets
(eg, "EST5EDT"). For what are now entirely historical reasons, various
parts of the system cope with different subsets of these three types.
I want to get to a state where you can use any of them in any context
and it Just Works. (While we are at it, we need to make the set of
recognized zone names user-configurable; the australian_timezones kluge
satisfies our contributors Down Under, but there are a lot of unhappy
people still, because for instance IST means different things in Israel
and India.)

regards, tom lane

#13Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#12)
Re: timestamp with time zone a la sql99

That is needed no matter what change you do if you want old programs that
use the current timestamp with time zone to work. Today you don't get back
the same time zone as you insert, programs might depend on that.

[ shrug... ] We've made much larger changes than that in the name of
standards compliance.

BTW, even if you do want output like that, that doesn't make two
datatypes a good idea. It'd be better to add a couple of DateStyle-like
formatting options:
* rotate all timestamps into current TimeZone for display, or not;
* display the timezone numerically, or as originally given.

A DateStyle kind of GUC variable is a lot less dangerous than what you
were proposing, because getting it wrong doesn't mean you have the wrong
data stored in the database ...

regards, tom lane

#14Dennis Bjorklund
db@zigo.dhs.org
In reply to: Tom Lane (#10)
Re: timestamp with time zone a la sql99

On Fri, 22 Oct 2004, Tom Lane wrote:

behavior. The spec says you can put a numeric-GMT-offset zone in and
get a numeric-GMT-offset zone out. We can do that and also support
named, possibly DST-aware zones.

So if I understand you correctly you are planning to extend the current
timestamp type to work with both named time zones and HH:MM ones? I didn't
think you wanted the last one since your plan was to store a UTC+OID where
the OID pointed to a named time zone. And I guess that you don't plan to
add 00:00, 00:01, 00:02, ... as named zones with an OID.

--
/Dennis Bj�rklund

#15Josh Berkus
josh@agliodbs.com
In reply to: Dennis Bjorklund (#14)
Re: timestamp with time zone a la sql99

Tom,

As far as I can tell, Dennis is planning slavish adherence to the spec,
which will mean that the datatype is unable to cope effectively with
daylight-savings issues.  So I'm unconvinced that it will be very
helpful to you for remembering local time in addition to true
(universal) time.

As somebody who codes calendar apps, I have to say that I have yet to see an
implementation of time zones which is at all useful for this purpose,
including the current implementation. My calendar apps on PostgreSQL 7.4
use "timestamp without time zone" and keep the time zone in a seperate field.

The reason is simple: our current implementation, which does include DST,
does not include any provision for the exceptions to DST -- such as Arizona
-- or for the difference between "1 day" and "24 hours". (Try adding "30
days" to "2004-10-05 10:00 PDT", you'll see what I mean). Nor do I see a
way out of this without raising the complexity, and configurability, level of
timezones significantly.

So if we're going to be broken (at least from the perspective of calendar
applications) we might as well be broken in a spec-compliant way.

--
Josh Berkus
Aglio Database Solutions
San Francisco

#16Tom Lane
tgl@sss.pgh.pa.us
In reply to: Josh Berkus (#15)
Re: timestamp with time zone a la sql99

Josh Berkus <josh@agliodbs.com> writes:

The reason is simple: our current implementation, which does include DST,
does not include any provision for the exceptions to DST -- such as Arizona

Say what?

regression=# set timezone to 'MST7MDT';
SET
regression=# select now();
now
-------------------------------
2004-10-25 11:52:47.093538-06
(1 row)

regression=# set timezone to 'US/Arizona';
SET
regression=# select now();
now
-------------------------------
2004-10-25 10:52:49.441559-07
(1 row)

-- or for the difference between "1 day" and "24 hours". (Try adding "30
days" to "2004-10-05 10:00 PDT", you'll see what I mean).

This is the point about how interval needs to treat "day" as different
from "24 hours". I agree with that; the fact that it's not done already
is just a reflection of limited supply of round tuits. I think it's
orthogonal to the question of how flexible timestamp with time zone
needs to be, though.

Nor do I see a way out of this without raising the complexity, and
configurability, level of timezones significantly.

This does not seem to me to be an argument why timestamp with time zone
ought to be incapable of dealing with DST-aware time zones. That simply
guarantees that calendar apps won't be able to use the datatype. If
they still can't use it when it can do that, then we can look at the
next blocking factor.

So if we're going to be broken (at least from the perspective of calendar
applications) we might as well be broken in a spec-compliant way.

I have not said that we can't comply with the spec. I have said that
our ambitions need to be higher than merely complying with the spec.

regards, tom lane

#17Josh Berkus
josh@agliodbs.com
In reply to: Tom Lane (#16)
Re: timestamp with time zone a la sql99

Tom,

regression=# set timezone to 'US/Arizona';
SET
regression=# select now();
now
-------------------------------
2004-10-25 10:52:49.441559-07

Wow! When did that get fixed? How do I keep track of this stuff if you
guys keep fixing it? ;-)

Of course, it would be very helpful if the result above could display
"Arizona" instead of the non-specific "-07", but I'm pretty sure that's
already a TODO.

This is the point about how interval needs to treat "day" as different
from "24 hours". I agree with that; the fact that it's not done already
is just a reflection of limited supply of round tuits.

Well, when I first brought up the issue (2001) I was shot down on the basis of
spec-compliance, since SQL92 recognizes only Year/Month and
Day/Hour/Minute/etc. partitions. Glad it's up for consideration again.

Come to think of it, it was Thomas Lockhart who shot down the idea of fixing
Interval, and he's retired now ...

This does not seem to me to be an argument why timestamp with time zone
ought to be incapable of dealing with DST-aware time zones. That simply
guarantees that calendar apps won't be able to use the datatype. If
they still can't use it when it can do that, then we can look at the
next blocking factor.

That's definitely a progressive attitude .... pardon me for being pessimistic.

I have not said that we can't comply with the spec. I have said that
our ambitions need to be higher than merely complying with the spec.

Hmmm ... well, does the spec specifically prohibit DST, or just leave it out?

--
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

#18Tom Lane
tgl@sss.pgh.pa.us
In reply to: Josh Berkus (#17)
Re: timestamp with time zone a la sql99

Josh Berkus <josh@agliodbs.com> writes:

regression=# set timezone to 'US/Arizona';
SET
regression=# select now();
now
-------------------------------
2004-10-25 10:52:49.441559-07

Wow! When did that get fixed? How do I keep track of this stuff if you
guys keep fixing it? ;-)

Of course, it would be very helpful if the result above could display
"Arizona" instead of the non-specific "-07", but I'm pretty sure that's
already a TODO.

Well, that is *exactly what I'm talking about*. I want timestamp with
time zone to carry "US/Arizona" not just "-07". Obviously there needs
to be some option to get the latter displayed when that's all you want,
but internally a value of the datatype needs to be able to carry full
knowledge of which timezone it's supposed to be in. Dumbing that down
to a simple numeric GMT offset isn't good enough.

I have not said that we can't comply with the spec. I have said that
our ambitions need to be higher than merely complying with the spec.

Hmmm ... well, does the spec specifically prohibit DST, or just leave it out?

It just doesn't talk about it AFAICS.

To comply with the spec we definitely need to be *able* to support
timezone values that are simple numeric GMT offsets. But I think we
ought also to be able to store values that are references to any of
the zic database entries. This looks to me like a straightforward
extension of the spec.

We went to all the trouble of importing src/timezone in order that we
could make a significant upgrade in our timezone capability, and now
it's time to take the steps that that enables. Before we were limited
to the lowest-common-denominator of the libc timezone routines on all
our different platforms, but now we are not...

regards, tom lane

#19Dennis Bjorklund
db@zigo.dhs.org
In reply to: Josh Berkus (#17)
Re: timestamp with time zone a la sql99

On Mon, 25 Oct 2004, Josh Berkus wrote:

Hmmm ... well, does the spec specifically prohibit DST, or just leave it
out?

It doesn't discuss it. According to the spec a timestamp with time zone is
a UTC value + a HH:MM offset from GMT. And intervals in the spec is either
a year-month value or a day-time value. One can only compare year-month
values with each other and day-time values with each other. So they avoid
the problem of the how many days is a month by not allowing it.

The spec is not a full solution, it's also not a useless solution. I'm
happy as long as the spec is a subset of what pg implements. If not then I
would like to be able to have both but with different names or something
similar (but I think that should not be needed).

--
/Dennis Bj�rklund

#20Josh Berkus
josh@agliodbs.com
In reply to: Dennis Bjorklund (#19)
Re: timestamp with time zone a la sql99

Dennis,

It doesn't discuss it. According to the spec a timestamp with time zone is
a UTC value + a HH:MM offset from GMT. And intervals in the spec is either
a year-month value or a day-time value. One can only compare year-month
values with each other and day-time values with each other. So they avoid
the problem of the how many days is a month by not allowing it.

That's not what Tom and I were talking about. The issue is that the spec
defines Days/Weeks as being an agglomeration of hours and not an atomic
entity like Months/Years are. This leads to some wierd and
calendar-breaking behavior when combined with DST, for example:

template1=> select '2004-10-09 10:00 PDT'::TIMESTAMPTZ + '45 days'::INTERVAL
template1-> ;
?column?
------------------------
2004-11-23 09:00:00-08
(1 row)

Because of the DST shift, you get an hour shift which is most decidely not
anything real human beings would expect from a calendar. The answer is to
try-partition INTERVAL values, as:

Hour/Minute/Second/ms
Day/Week
Month/Year

However, this could be considered to break the spec; certainly Thomas thought
it did. My defense is that the SQL committee made some mistakes, and
interval is a big one.

--
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

#21Tom Lane
tgl@sss.pgh.pa.us
In reply to: Josh Berkus (#20)
#22Dennis Bjorklund
db@zigo.dhs.org
In reply to: Josh Berkus (#20)
#23Dennis Bjorklund
db@zigo.dhs.org
In reply to: Josh Berkus (#20)
#24Dennis Bjorklund
db@zigo.dhs.org
In reply to: Josh Berkus (#20)
#25Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Bjorklund (#24)
#26Bruno Wolff III
bruno@wolff.to
In reply to: Dennis Bjorklund (#24)
#27Dennis Bjorklund
db@zigo.dhs.org
In reply to: Tom Lane (#25)
#28Josh Berkus
josh@agliodbs.com
In reply to: Dennis Bjorklund (#22)
#29Dennis Bjorklund
db@zigo.dhs.org
In reply to: Josh Berkus (#28)
#30Tom Lane
tgl@sss.pgh.pa.us
In reply to: Josh Berkus (#28)
#31Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Tom Lane (#18)
#32Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dennis Bjorklund (#14)
#33Tom Lane
tgl@sss.pgh.pa.us
In reply to: Christopher Kings-Lynne (#31)
#34Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#32)
#35Bruce Momjian
bruce@momjian.us
In reply to: Dennis Bjorklund (#1)