Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] INTERVAL data type and libpq - what format?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>, Sam Mason <sam(at)samason(dot)me(dot)uk>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [GENERAL] INTERVAL data type and libpq - what format?
Date: 2009-06-01 00:05:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-hackers
I wrote:
> In a related example,

> regression=# select interval '123 11' day;        
>  interval 
> ----------
>  134 days
> (1 row)

> we seem to be adding the 123 and 11 together.  This is, um,
> surprising behavior ... I'd be inclined to think throwing an
> error is more appropriate.

I looked into this and found out why the code wasn't throwing an error
already: it seems to be a case of ancient bit-shaving.  DecodeInterval
maintains an integer bitmask of field types it's seen already, and
reports an error if a new field's bit is already set in that mask.
However, DAY and WEEK are coded to share a bit, as are YEAR, DECADE,
CENTURY, and MILLENIUM; which means the code can't throw error for
multiple occurrences of any one of those field types.  However, there
is room in the mask for all these fields to have their own bits, so
the attached proposed patch just does that.

The potential objections I can see to this patch are:

(1) it eats more than half of the remaining bits in the DTK_M() mask.
This doesn't seem to me to be a big problem --- it's not like people
are likely to come up with many more time intervals for us to support.
Also we could probably shave some bits by eliminating redundancies
if we had to.  (For instance, I think IGNORE_DTF could safely be given
a code above 31 since there's no need for it to be in the bitmasks.)

(2) WEEK, DECADE, CENTURY, and MILLENNIUM are too generic to be used
as #define names without some kind of prefix or suffix.  This is a real
risk, but considering the other #defines in this list have no prefix or
suffix, it seems inconsistent to put one on these.  The buildfarm should
tell us soon enough if there's a real problem (the code does compile
cleanly for me).  If we do have a problem, we should add a prefix/suffix
to all these macros at once; but I'd rather not do that as part of a
small bugfix.


			regards, tom lane

In response to

pgsql-hackers by date

Next:From: Mark WongDate: 2009-06-01 00:08:07
Subject: survey of table blocksize changes
Previous:From: David E. WheelerDate: 2009-05-31 23:52:24
Subject: Re: search_path improvements

pgsql-general by date

Next:From: j-listsDate: 2009-06-01 06:29:36
Subject: Foreign key verification trigger conditions
Previous:From: Tom LaneDate: 2009-05-31 21:35:33
Subject: Re: INTERVAL SECOND limited to 59 seconds?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group