473,788 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

interval output format available that removes ambiguity ?

I have the need to output intervals (ages in this case).
PostgreSQL takes great care to handle months correctly (eg
take into account varying months lengths). This is only
possible if either end point or start point of an interval are
known. For post processing some of the ambiguity of what
"2 mons" means would be removed if "61 days" was returned.

Is there a way to tell PostgreSQL to return that type of
interval (eg use weeks, days, hours, minutes, seconds, ...
but not months and perhaps not even years [leap years, etc]) ?
to_char(interva l, text) doesn't work as it is applied after
the fact.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #1
10 2265
On Tue, May 04, 2004 at 12:24:37 +0200,
Karsten Hilbert <Ka************ *@gmx.net> wrote:
I have the need to output intervals (ages in this case).
PostgreSQL takes great care to handle months correctly (eg
take into account varying months lengths). This is only
possible if either end point or start point of an interval are
known. For post processing some of the ambiguity of what
"2 mons" means would be removed if "61 days" was returned.
This is sort of done now, but the months part of the interval will be
treated as 30 days.
Is there a way to tell PostgreSQL to return that type of
interval (eg use weeks, days, hours, minutes, seconds, ...
but not months and perhaps not even years [leap years, etc]) ?
to_char(interva l, text) doesn't work as it is applied after
the fact.


You can extract "epoch" from the interval to get the total number of
seconds in the interval (converting months to the number of seconds
in 30 days) and then divide that by the appropiate amount.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #2
On Tue, May 04, 2004 at 12:24:37 +0200,
Karsten Hilbert <Ka************ *@gmx.net> wrote:
I have the need to output intervals (ages in this case).
PostgreSQL takes great care to handle months correctly (eg
take into account varying months lengths). This is only
possible if either end point or start point of an interval are
known. For post processing some of the ambiguity of what
"2 mons" means would be removed if "61 days" was returned.
This is sort of done now, but the months part of the interval will be
treated as 30 days.
Is there a way to tell PostgreSQL to return that type of
interval (eg use weeks, days, hours, minutes, seconds, ...
but not months and perhaps not even years [leap years, etc]) ?
to_char(interva l, text) doesn't work as it is applied after
the fact.


You can extract "epoch" from the interval to get the total number of
seconds in the interval (converting months to the number of seconds
in 30 days) and then divide that by the appropiate amount.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #3
Bruno,

thanks for answering. I still have some questions:
I have the need to output intervals (ages in this case).
PostgreSQL takes great care to handle months correctly (eg
take into account varying months lengths). This is only
possible if either end point or start point of an interval are
known. For post processing some of the ambiguity of what
"2 mons" means would be removed if "61 days" was returned.
This is sort of done now, but the months part of the interval will be
treated as 30 days.

Are you saying that when PostgreSQL returns "... 3 mons ..."
as a representation of an interval I can safely assume that
when it calculated the number of months it used 30 days
regardless of the actual length of the month ? I couldn't find
that number mentioned anywhere and had not browsed the source
yet. That would also be contrary to what I thought. I assumed
the following would happen:

select age('1999-2-2', '1999-3-2');
select age('1999-5-2', '1999-6-2');

would both return "1 mon" (despite the first one being 28 days
and the second one being 31 days).

I am now looking for a way to say:

select age('1999-2-2', '1999-3-2', without months);
select age('1999-5-2', '1999-6-2', without months);

and get "28 days" in the first and "31 days" in the second
result.

However, if you say that "1 mon" is always considered 30 days
in this context I would expect to receive:

1) "1 mon -2 days" (it would return 28 days of course, I know)
2) "1 mon 1 day"

Neither 7.1 nor 7.4 return that.
You can extract "epoch" from the interval to get the total number of
seconds in the interval (converting months to the number of seconds
in 30 days) and then divide that by the appropiate amount.

That only works if the above holds true, eg the month must be
fixed to 30 days by the calculation *generating* the interval
representation. Applying epoch *after* the fact is no good,
does it, because the epoch() code won't know whether "1 mons"
is to be 28 or 29 or 30 or 31 days.

Am I missing something here ?

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #4
Bruno,

thanks for answering. I still have some questions:
I have the need to output intervals (ages in this case).
PostgreSQL takes great care to handle months correctly (eg
take into account varying months lengths). This is only
possible if either end point or start point of an interval are
known. For post processing some of the ambiguity of what
"2 mons" means would be removed if "61 days" was returned.
This is sort of done now, but the months part of the interval will be
treated as 30 days.

Are you saying that when PostgreSQL returns "... 3 mons ..."
as a representation of an interval I can safely assume that
when it calculated the number of months it used 30 days
regardless of the actual length of the month ? I couldn't find
that number mentioned anywhere and had not browsed the source
yet. That would also be contrary to what I thought. I assumed
the following would happen:

select age('1999-2-2', '1999-3-2');
select age('1999-5-2', '1999-6-2');

would both return "1 mon" (despite the first one being 28 days
and the second one being 31 days).

I am now looking for a way to say:

select age('1999-2-2', '1999-3-2', without months);
select age('1999-5-2', '1999-6-2', without months);

and get "28 days" in the first and "31 days" in the second
result.

However, if you say that "1 mon" is always considered 30 days
in this context I would expect to receive:

1) "1 mon -2 days" (it would return 28 days of course, I know)
2) "1 mon 1 day"

Neither 7.1 nor 7.4 return that.
You can extract "epoch" from the interval to get the total number of
seconds in the interval (converting months to the number of seconds
in 30 days) and then divide that by the appropiate amount.

That only works if the above holds true, eg the month must be
fixed to 30 days by the calculation *generating* the interval
representation. Applying epoch *after* the fact is no good,
does it, because the epoch() code won't know whether "1 mons"
is to be 28 or 29 or 30 or 31 days.

Am I missing something here ?

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #5
On Tue, May 04, 2004 at 22:59:34 +0200,
Karsten Hilbert <Ka************ *@gmx.net> wrote:
Are you saying that when PostgreSQL returns "... 3 mons ..."
as a representation of an interval I can safely assume that
when it calculated the number of months it used 30 days
regardless of the actual length of the month ? I couldn't find
It only does this when there is no month to know the length of.
Offhand the only way I know of to get this is to extract the
epoch part of a month which combines the month/year part of the interval
with the week/day/hour/minute/second part without knowing which particular
months are being referred to.
that number mentioned anywhere and had not browsed the source
yet. That would also be contrary to what I thought. I assumed
the following would happen:

select age('1999-2-2', '1999-3-2');
select age('1999-5-2', '1999-6-2');

would both return "1 mon" (despite the first one being 28 days
and the second one being 31 days).
No it doesn't do that. In those examples it knows what particular months
are involved and can use the correct length.
I am now looking for a way to say:

select age('1999-2-2', '1999-3-2', without months);
select age('1999-5-2', '1999-6-2', without months);

and get "28 days" in the first and "31 days" in the second
result.
select '1999-3-2'::date - '1999-2-2'::date;
select '1999-6-2'::date - '1999-5-2'::date;

However, if you say that "1 mon" is always considered 30 days
in this context I would expect to receive:
That isn't what I said and that isn't what happens.

1) "1 mon -2 days" (it would return 28 days of course, I know)
2) "1 mon 1 day"

Neither 7.1 nor 7.4 return that.
You can extract "epoch" from the interval to get the total number of
seconds in the interval (converting months to the number of seconds
in 30 days) and then divide that by the appropiate amount. That only works if the above holds true, eg the month must be
fixed to 30 days by the calculation *generating* the interval
representation. Applying epoch *after* the fact is no good,
does it, because the epoch() code won't know whether "1 mons"
is to be 28 or 29 or 30 or 31 days.


Not exactly. Months are converted to 30 days in the above situation, but
not always.
Am I missing something here ?


Note that intervals store two different values in them. One is a time in
months and another is in some multiple (possibly 1) of seconds. Often one
or the other of these is zero, but not always.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #6
On Tue, May 04, 2004 at 22:59:34 +0200,
Karsten Hilbert <Ka************ *@gmx.net> wrote:
Are you saying that when PostgreSQL returns "... 3 mons ..."
as a representation of an interval I can safely assume that
when it calculated the number of months it used 30 days
regardless of the actual length of the month ? I couldn't find
It only does this when there is no month to know the length of.
Offhand the only way I know of to get this is to extract the
epoch part of a month which combines the month/year part of the interval
with the week/day/hour/minute/second part without knowing which particular
months are being referred to.
that number mentioned anywhere and had not browsed the source
yet. That would also be contrary to what I thought. I assumed
the following would happen:

select age('1999-2-2', '1999-3-2');
select age('1999-5-2', '1999-6-2');

would both return "1 mon" (despite the first one being 28 days
and the second one being 31 days).
No it doesn't do that. In those examples it knows what particular months
are involved and can use the correct length.
I am now looking for a way to say:

select age('1999-2-2', '1999-3-2', without months);
select age('1999-5-2', '1999-6-2', without months);

and get "28 days" in the first and "31 days" in the second
result.
select '1999-3-2'::date - '1999-2-2'::date;
select '1999-6-2'::date - '1999-5-2'::date;

However, if you say that "1 mon" is always considered 30 days
in this context I would expect to receive:
That isn't what I said and that isn't what happens.

1) "1 mon -2 days" (it would return 28 days of course, I know)
2) "1 mon 1 day"

Neither 7.1 nor 7.4 return that.
You can extract "epoch" from the interval to get the total number of
seconds in the interval (converting months to the number of seconds
in 30 days) and then divide that by the appropiate amount. That only works if the above holds true, eg the month must be
fixed to 30 days by the calculation *generating* the interval
representation. Applying epoch *after* the fact is no good,
does it, because the epoch() code won't know whether "1 mons"
is to be 28 or 29 or 30 or 31 days.


Not exactly. Months are converted to 30 days in the above situation, but
not always.
Am I missing something here ?


Note that intervals store two different values in them. One is a time in
months and another is in some multiple (possibly 1) of seconds. Often one
or the other of these is zero, but not always.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #7
Karsten Hilbert <Ka************ *@gmx.net> writes:
I am now looking for a way to say:
select age('1999-2-2', '1999-3-2', without months);
select age('1999-5-2', '1999-6-2', without months);
and get "28 days" in the first and "31 days" in the second
result.
Just subtract the two timestamps (or dates) instead of using age().
Then you get an interval that has no month component.
However, if you say that "1 mon" is always considered 30 days


He didn't say that. He said that when the system *must* convert a
month-based interval to days and it has no date reference for it,
it uses 30 days. Something like "now() + '1 month'::interva l"
will do the "right thing". This IMHO is the main application of
intervals with month components ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #8
Karsten Hilbert <Ka************ *@gmx.net> writes:
I am now looking for a way to say:
select age('1999-2-2', '1999-3-2', without months);
select age('1999-5-2', '1999-6-2', without months);
and get "28 days" in the first and "31 days" in the second
result.
Just subtract the two timestamps (or dates) instead of using age().
Then you get an interval that has no month component.
However, if you say that "1 mon" is always considered 30 days


He didn't say that. He said that when the system *must* convert a
month-based interval to days and it has no date reference for it,
it uses 30 days. Something like "now() + '1 month'::interva l"
will do the "right thing". This IMHO is the main application of
intervals with month components ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #9
Tom,
Just subtract the two timestamps (or dates) instead of using age().
Then you get an interval that has no month component. *That* was what I was looking for. Thanks !
He didn't say that. He said that when the system *must* convert a
month-based interval to days and it has no date reference for it,
it uses 30 days. Something like "now() + '1 month'::interva l"
will do the "right thing". This IMHO is the main application of
intervals with month components ...

I knew PostgreSQL would do the Right Thing(tm) where possible
and assume reasonable defaults where ambiguity exists. I just
didn't know how to tell it to return the right version of the
Right Thing.

As usual, sage advice.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

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

Nov 23 '05 #10

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

Similar topics

4
16606
by: Claudia Fong | last post by:
Hi Is there a way to change a date format dd/mm/yyyy to m/d/yy? I have a textBox where the user should put a date, but no matter what format the user input dd/mm/yyyy or m/d/yy, I need to convert it to this format: m/d/yy. Cheers!
6
7171
by: SJ | last post by:
howdy, In vb6 I could say If Time >#4:00:00 PM# And Time < #4:01:00 PM# Then 'Do Something End If Well, I don't see the Time function in vb.net. I have experimented with the TimeSpan object for capturing
4
2577
by: ziondreams | last post by:
I'm currently working on a system that will allow our 175+ clients that store their data on our databases to export the data to their systems (via webservice) and also call other web services to update pieces of that data in our systems. What I need help with is the ability to format the XML from the web service differently and dynamically. For example, every client has completely different data and data structures; I have to make it...
0
358
by: Karsten Hilbert | last post by:
I have the need to output intervals (ages in this case). PostgreSQL takes great care to handle months correctly (eg take into account varying months lengths). This is only possible if either end point or start point of an interval are known. For post processing some of the ambiguity of what "2 mons" means would be removed if "61 days" was returned. Is there a way to tell PostgreSQL to return that type of interval (eg use weeks, days,...
0
1818
by: Ian E. Morgan | last post by:
After being frustrated with the inflexible output of intervals, I've written a pl/pgsql function to do what I want, and hopefully some other people might find it useful. Output is a string that matches the output format of an interval as closely as possible, but rather than counting days as a fixed 24-hours, it recalculates days based on the number of hours in the desired 'day'. For example, this is very useful for summing up work time...
2
1825
by: pruebauno | last post by:
I am currently working on a tricky problem at work. I googled around a bit, but "time intervals" did not come up with anything useful. Although I have some rough idea of how I could solve it, I still would value some input. I have information of (It has only couple dozen entries.) ServiceNum, DollarCost and a input database table in the form (several GBytes): ClientNumber (CN), BeginDate(BD), EndDate(ED),
3
6519
by: alex.fishman | last post by:
Hi, I need to implement a container for integer intervals, something that looks like (1,5), (10,20), (4,7), etc. The container has to be of the following properties: search for an arbitratry interval for intersection in O(log n) or O(1) if possible, insert and delete in O(log n). Does this sound simple? Is there any reference implementation that I can look at?
2
1945
by: JP SIngh | last post by:
Hi All We are creating a multi-region ASP application which will be using SQL Server 2000. As our users exist in multiple location i.e. UK, US, Australia how can we distinguish that the date the user is entering is captured correctly i.e. no confusion with DD/MM/YYYY format. I guess to remove database ambiguity I am going to use the format YYYYMMDD
1
1364
by: russ | last post by:
Hi all, Very new to Python - but excited to see what is possible - it sounds very suitable for a project of mine I need a little help with. I've got an executable which writes out data to stdout in a CSV sort of format - I'd like to grab the data from stdout and create stats from it at a regular interval, i.e. every 10 min. Probably push the stats out to a CSV file.
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.