Re: [HACKERS] [SQL] Interval subtracting

2006-03-08 Thread Markus Schaber
Hi, Scott, Scott Marlowe wrote: But it isn't '-2 months, -1 day'. I think what you are saying is what I am saying, that we should make the signs consistent. Pretty much. It just seems wrong to have different signs in what is essentially a single unit. We don't say 42 degrees, -12 minutes

Re: [HACKERS] [SQL] Interval subtracting

2006-03-08 Thread Scott Marlowe
On Wed, 2006-03-08 at 06:07, Markus Schaber wrote: Hi, Scott, Scott Marlowe wrote: But it isn't '-2 months, -1 day'. I think what you are saying is what I am saying, that we should make the signs consistent. Pretty much. It just seems wrong to have different signs in what is

Re: [HACKERS] [SQL] Interval subtracting

2006-03-08 Thread Tom Lane
Scott Marlowe [EMAIL PROTECTED] writes: For same reasons, i.e. a need for precision, I find it hard to accept the idea of mixing positive and negative units in the same interval. The semantics are perfectly well defined, so I don't buy this. regards, tom lane

Re: [HACKERS] [SQL] Interval subtracting

2006-03-03 Thread Mark Dilger
Attached is the new patch. To summarize: - new function justify_interval(interval) - modified function justify_hours(interval) - modified function justify_days(interval) These functions are defined to meet the requirements as discussed in this thread. Specifically: - justify_hours

Re: [HACKERS] [SQL] Interval subtracting

2006-03-02 Thread Tom Lane
Mark Dilger [EMAIL PROTECTED] writes: Tom Lane wrote: The problem is that you can't determine what answer justify_days would give without using the assumption 1 month == 30 days, which is an assumption that justify_hours must not depend on. Ahhh. So the fact that justify_days already makes

Re: [HACKERS] [SQL] Interval subtracting

2006-03-02 Thread Scott Marlowe
On Thu, 2006-03-02 at 00:45, Hannu Krosing wrote: Ühel kenal päeval, K, 2006-03-01 kell 14:36, kirjutas Scott Marlowe: But it isn't '-2 months, -1 day'. I think what you are saying is what I am saying, that we should make the signs consistent. Pretty much. It just seems wrong to

Re: [HACKERS] [SQL] Interval subtracting

2006-03-02 Thread Hannu Krosing
Ühel kenal päeval, N, 2006-03-02 kell 10:13, kirjutas Scott Marlowe: On Thu, 2006-03-02 at 00:45, Hannu Krosing wrote: Ühel kenal päeval, K, 2006-03-01 kell 14:36, kirjutas Scott Marlowe: .. We don't say 42 degrees, -12 minutes when measuring arc, do we? Then again, maybe some folks do.

Re: [HACKERS] [SQL] Interval subtracting

2006-03-02 Thread Martijn van Oosterhout
On Thu, Mar 02, 2006 at 10:06:26AM -0800, Mark Dilger wrote: I used grep -R to find all locations where interval_justify_time is mentioned, and for each one added an analogous entry for my new function interval_justify. But I get lost where OID=1175 is associated with

Re: [HACKERS] [SQL] Interval subtracting

2006-03-02 Thread Tom Lane
Mark Dilger [EMAIL PROTECTED] writes: I've written the interval_justify() function but the parser does not know about it yet. The pg_proc change is the only source change you need for that, but afterwards you need to update the postgres.bki file (handled by make and make install in

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Milen A. Radev [EMAIL PROTECTED] writes: Milorad Poluga напи�а: SELECT '10 years 1 mons 1 days'::interval - '9 years 10 mons 15 days'::interval ?column? --- 3 mons -14 days Why not '2 mons 16 days' ? Please read the last paragraph in section

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Mark Dilger wrote: Tom Lane wrote: Milen A. Radev [EMAIL PROTECTED] writes: Milorad Poluga : SELECT '10 years 1 mons 1 days'::interval - '9 years 10 mons 15 days'::interval ?column? --- 3 mons -14 days Why not '2 mons 16 days' ? Please

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Mark Dilger wrote: Tom Lane wrote: Milen A. Radev [EMAIL PROTECTED] writes: Milorad Poluga напи�а: SELECT '10 years 1 mons 1 days'::interval - '9 years 10 mons 15 days'::interval ?column?--- 3 mons -14 days Why not '2 mons 16 days' ? Please read the last

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Jim C. Nasby
On Wed, Mar 01, 2006 at 12:59:29PM -0500, Bruce Momjian wrote: Good question. Should we restrict days to 0 - 30 or -30 - 30? The current system does the later: test= select justify_days('-45 days'); justify_days -- -1 mons -15 days (1

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Mark Dilger wrote: select justify_hours('-73 hours'::interval); justify_hours --- -4 days +23:00:00 select justify_days('-62 days'::interval); justify_days -- -3 mons +28 days I find the last two results somewhat

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Stephan Szabo wrote: justify_days doesn't currently do anything with this result --- it thinks its charter is only to reduce day components that are = 30 days. However, I think a good case could be made that it should normalize negative days too; that is, the invariant on its result should

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Scott Marlowe
On Wed, 2006-03-01 at 14:18, Bruce Momjian wrote: Stephan Szabo wrote: justify_days doesn't currently do anything with this result --- it thinks its charter is only to reduce day components that are = 30 days. However, I think a good case could be made that it should normalize

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Scott Marlowe wrote: On Wed, 2006-03-01 at 14:18, Bruce Momjian wrote: Stephan Szabo wrote: justify_days doesn't currently do anything with this result --- it thinks its charter is only to reduce day components that are = 30 days. However, I think a good case could be made that it

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes: I don't think we can accept a change that takes a negative and turns it into a positive and negative. Yeah, I find the patch's changes to the regression results pretty disturbing. Perhaps the correct definition ought to be like if month part = 0

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Hannu Krosing
Ühel kenal päeval, K, 2006-03-01 kell 15:18, kirjutas Bruce Momjian: Stephan Szabo wrote: justify_days doesn't currently do anything with this result --- it thinks its charter is only to reduce day components that are = 30 days. However, I think a good case could be made that it should

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Stephan Szabo
On Wed, 1 Mar 2006, Hannu Krosing wrote: Ühel kenal päeval, K, 2006-03-01 kell 15:18, kirjutas Bruce Momjian: Stephan Szabo wrote: justify_days doesn't currently do anything with this result --- it thinks its charter is only to reduce day components that are = 30 days. However, I

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Hannu Krosing wrote: ?hel kenal p?eval, K, 2006-03-01 kell 15:18, kirjutas Bruce Momjian: Stephan Szabo wrote: justify_days doesn't currently do anything with this result --- it thinks its charter is only to reduce day components that are = 30 days. However, I think a good case

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Tom Lane wrote: Bruce Momjian pgman@candle.pha.pa.us writes: I don't think we can accept a change that takes a negative and turns it into a positive and negative. Yeah, I find the patch's changes to the regression results pretty disturbing. Perhaps the correct definition ought to be

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Hannu Krosing [EMAIL PROTECTED] writes: But unfortunately '2 mons -1 days' '1 mons 29 days' If I want something to happen 1 day less than two months from dome date, then the only way to say that consistently *is* '2 mons -1 days'. Sure, but if you want to represent that then you don't pass

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Bruce Momjian pgman@candle.pha.pa.us writes: I don't think we can accept a change that takes a negative and turns it into a positive and negative. Yeah, I find the patch's changes to the regression results pretty disturbing. Perhaps the correct definition ought to be like

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Hannu Krosing wrote: But unfortunately '2 mons -1 days' '1 mons 29 days' If I want something to happen 1 day less than two months from dome date, then the only way to say that consistently *is* '2 mons -1 days'. Correct me if I am wrong, but I thought that justify_days would only be called

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Mark Dilger [EMAIL PROTECTED] writes: Tom Lane wrote: I guess I would expect a good result to satisfy one of these three cases: * month 0 and 0 = day 30 * month 0 and -30 day = 0 * month = 0 and -30 day 30 If you believe that then 1 month -95 days should justify to -2

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Scott Marlowe
On Wed, 2006-03-01 at 14:27, Bruce Momjian wrote: Scott Marlowe wrote: On Wed, 2006-03-01 at 14:18, Bruce Momjian wrote: Stephan Szabo wrote: justify_days doesn't currently do anything with this result --- it thinks its charter is only to reduce day components that are = 30

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Mark Dilger [EMAIL PROTECTED] writes: Tom Lane wrote: I guess I would expect a good result to satisfy one of these three cases: * month 0 and 0 = day 30 * month 0 and -30 day = 0 * month = 0 and -30 day 30 If you believe that then 1 month -95

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Mark Dilger [EMAIL PROTECTED] writes: The current code (without the patch) behaves as follows: select justify_days(justify_hours('1 month 95 days -36:00:00'::interval)); justify_days - 4 mons 4 days -12:00:00 So? If we liked the current behavior

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Mark Dilger [EMAIL PROTECTED] writes: The current code (without the patch) behaves as follows: select justify_days(justify_hours('1 month 95 days -36:00:00'::interval)); justify_days - 4 mons 4 days -12:00:00 So? If we liked the

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Mark Dilger wrote: Your proposal is that justify_hours borrows 24 hours from the days column in order to bring the -12 hours up to a positive 12 hours. Should it only do that if the days column is a positive number? What if it is negative? I think we all agree on the following but

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Bruce Momjian wrote: Mark Dilger wrote: Your proposal is that justify_hours borrows 24 hours from the days column in order to bring the -12 hours up to a positive 12 hours. Should it only do that if the days column is a positive number? What if it is negative? I think we all agree on the

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
A new patch is attached. Please note the regression differences. mark Index: src/backend/utils/adt/timestamp.c === RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v retrieving revision 1.160 diff --context=5

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes: Imagine this: '1 mons -2 days -12:00:00' Which sign do we head to for this? For justify_hours, if we don't look at the months it remains unchange, but calling justify_days we get: '28 days -12:00:00' which is wrong (negative and

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Mark Dilger [EMAIL PROTECTED] writes: Am I correct that the second case should still have negative hours? Yes... If so, then justify_hours(...) needs to examine the sign of the days and months portion of the interval while performing its work. No, it should ignore the

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Tom Lane wrote: Bruce Momjian pgman@candle.pha.pa.us writes: Imagine this: '1 mons -2 days -12:00:00' Which sign do we head to for this? For justify_hours, if we don't look at the months it remains unchange, but calling justify_days we get: '28 days -12:00:00' which

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Bruce Momjian wrote: If we do that, we should just call it justify_interval(). I am thinking this is the direction to go, and for people who want more control they use the justify_hours and justify_days, and those are left unchanged. I agree. Let's leave the existing functions alone. I can

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes: Tom Lane wrote: Based on that, I guess I have to change my vote: justify_hours should still not look at the month (because it shouldn't use the month=30days assumption), but justify_days should be changed to be effectively a combination of both

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Well, the question is whether justify_days has a sane definition that is different from this. Based on your example, I'm not seeing one. Backwards compatibility is probably more important than sanity. Let's just deprecate the existing functions and recommend that people use

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Tom Lane wrote: Bruce Momjian pgman@candle.pha.pa.us writes: Tom Lane wrote: Based on that, I guess I have to change my vote: justify_hours should still not look at the month (because it shouldn't use the month=30days assumption), but justify_days should be changed to be effectively a

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes: Well, the question is whether justify_days has a sane definition that is different from this. Based on your example, I'm not seeing one. Uh, justify days only deals with days -- months conversions. There is no processing for hours. I don't

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Mark Dilger [EMAIL PROTECTED] writes: Bruce Momjian wrote: If we do that, we should just call it justify_interval(). I am thinking this is the direction to go, and for people who want more control they use the justify_hours and justify_days, and those are left unchanged. I agree. Let's

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Mark Dilger [EMAIL PROTECTED] writes: This overall design seems more flexible than Tom's recent post in which he stated that justify_days should call justify_hours internally. AFAIR I said the exact opposite. regards, tom lane ---(end of

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Bruce Momjian
Mark Dilger wrote: Tom Lane wrote: Well, the question is whether justify_days has a sane definition that is different from this. Based on your example, I'm not seeing one. Backwards compatibility is probably more important than sanity. Let's just deprecate the existing functions and

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Mark Dilger [EMAIL PROTECTED] writes: This overall design seems more flexible than Tom's recent post in which he stated that justify_days should call justify_hours internally. AFAIR I said the exact opposite. regards, tom lane Tom Lane also wrote:

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Bruce Momjian wrote: Even if we had people do: justify_hours(justify_days(justify_hours())) I don't think that would do what we want in all cases. Consider '1 mon -1 hour'. That should be '29 days 23 hours' but neither existing function, even if modified, will allow us to return

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Mark Dilger [EMAIL PROTECTED] writes: justify_days(justify_hours(...)) fixes *everything* in the most recently submitted patch, regardless of the convoluted case you invent. There is no data for which it won't work. If so, one function or the other is cheating. Per discussion,

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Mark Dilger [EMAIL PROTECTED] writes: justify_days(justify_hours(...)) fixes *everything* in the most recently submitted patch, regardless of the convoluted case you invent. There is no data for which it won't work. If so, one function or the other is cheating. Per

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tom Lane
Mark Dilger [EMAIL PROTECTED] writes: Tom Lane wrote: If so, one function or the other is cheating. That depends what you mean by cheating. The justify_hours function looks to see what answer justify_days would give, but does not actually change the data. I described this all earlier and I

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Mark Dilger
Tom Lane wrote: Mark Dilger [EMAIL PROTECTED] writes: Tom Lane wrote: If so, one function or the other is cheating. That depends what you mean by cheating. The justify_hours function looks to see what answer justify_days would give, but does not actually change the data. I described

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Hannu Krosing
Ühel kenal päeval, K, 2006-03-01 kell 14:36, kirjutas Scott Marlowe: But it isn't '-2 months, -1 day'. I think what you are saying is what I am saying, that we should make the signs consistent. Pretty much. It just seems wrong to have different signs in what is essentially a single

Re: [HACKERS] [SQL] Interval subtracting

2006-03-01 Thread Tino Wildenhain
Hannu Krosing schrieb: Ühel kenal päeval, K, 2006-03-01 kell 14:36, kirjutas Scott Marlowe: ... But we do say both quarter past three (3 hours 15 min) and quarter to four (4 hours -15 min) when talking about time. but luckily we dont write it ;) Some people say (like ) this: quarter past 3,

Re: [HACKERS] [SQL] Interval subtracting

2006-02-18 Thread Tom Lane
Milen A. Radev [EMAIL PROTECTED] writes: Milorad Poluga написа: SELECT '10 years 1 mons 1 days'::interval - '9 years 10 mons 15 days'::interval ?column? --- 3 mons -14 days Why not '2 mons 16 days' ? Please read the last paragraph in section 8.5.1.4 of the

Re: [HACKERS] [SQL] Interval subtracting

2006-02-18 Thread Stephan Szabo
On Sat, 18 Feb 2006, Tom Lane wrote: Milen A. Radev [EMAIL PROTECTED] writes: Milorad Poluga : SELECT '10 years 1 mons 1 days'::interval - '9 years 10 mons 15 days'::interval ?column? --- 3 mons -14 days Why not '2 mons 16 days' ? Please read the last