Re: Fwd: [BUGS] BUG #14850: Implement optinal additinal parameter for 'justify' date/time function

From: KES <kes-kes(at)yandex(dot)ru>
To: Brian Dunavant <brian(at)omniti(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Fwd: [BUGS] BUG #14850: Implement optinal additinal parameter for 'justify' date/time function
Date: 2017-10-13 08:13:43
Message-ID: 43251507882423@web57j.yandex.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general pgsql-hackers

<div>huh... how did I miss `age` function???</div><div> </div><div>Thanks. I give me the idea. I will add 5days when the month of day is greater or equal to 28</div><div> </div><div><div>select age( '2016-02-29'::date +'5days'::interval, '2016-01-31'::date+'5days'::interval );</div><div>  age  </div><div>-------</div><div> 1 mon</div><div>(1 row)</div><div> </div><div>It seems resolves my issue</div><div> </div><div> </div></div><div><br /></div><div><br /></div><div>12.10.2017, 17:38, "Brian Dunavant" &lt;brian(at)omniti(dot)com&gt;:</div><blockquote type="cite"><div dir="ltr">A 'month' is an abstract measurement of time.  Sometimes it's 29 days, 30, or 31.   You cannot say "I have 30 days, how many months is that?" because the answer is "it depends".<div><br /></div><div>&lt;date&gt; - &lt;date&gt; gives you an interval in days.   In your example, you took Jan 31 2016 and added "1 month".  Postgres says "I know feb 2016 is 29 days" and did it automatically for you.   When you then subtracted Jan 31 2016, you now have "29 days".   Postgres can no longer say "that is 1 month" because you cannot go that direction.</div><div><br /></div><div>You are also using extract(month from X) incorrectly if you want the number of months between any time period.   That will only return a value between 0 and 11.</div><div><br /></div><div>It will also be difficult because you are starting from a random day in the month, making it hard to really know what you mean.  Postgres' age() function may be able to help you with 'months'.  </div><div><div><br /></div><div>flpg=# select age( '<span>2016-02-01</span>'::timestamp, '<span>2016-01-01</span>'::timestamp );</div><div>  age</div><div>-------</div><div> 1 mon</div></div><div><br /></div><div><div>flpg=# select age( '<span>2016-02-29</span>'::timestamp, '<span>2016-01-31</span>'::timestamp );</div><div>   age</div><div>---------</div><div> 29 days</div><div>(1 row)</div></div><div><br /></div><div><div>flpg=# select age( '<span>2016-03-01</span>'::timestamp, '<span>2016-01-31</span>'::timestamp );</div><div>     age</div><div>-------------</div><div> 1 mon 1 day</div></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div></div><div><br /><div>On Thu, Oct 12, 2017 at 4:00 AM, KES <span dir="ltr">&lt;<a href="mailto:kes-kes(at)yandex(dot)ru" target="_blank">kes-kes(at)yandex(dot)ru</a>&gt;</span> wrote:<br /><blockquote style="margin:0 0 0 0.8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><br /></div><div><br /></div><div>-------- Пересылаемое сообщение--------</div><div>11.10.2017, 17:12, "Pavel Stehule" &lt;<a href="mailto:pavel(dot)stehule(at)gmail(dot)com" target="_blank">pavel(dot)stehule(at)gmail(dot)com</a>&gt;:</div><div><div><div><br /></div><div><div dir="ltr">Hi<br /><div><div><br /><div><span><span>2017-10-11 12</span></span>:35 GMT+02:00 <span dir="ltr">&lt;<a href="mailto:kes-kes(at)yandex(dot)ru" target="_blank">kes-kes(at)yandex(dot)ru</a>&gt;</span>:<br /><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">The following bug has been logged on the website:<br />
<br />
Bug reference:      14850<br />
Logged by:          Eugen Konkov<br />
Email address:      <a href="mailto:kes-kes(at)yandex(dot)ru" target="_blank">kes-kes(at)yandex(dot)ru</a><br />
PostgreSQL version: 10.0<br />
Operating system:   Linux mint 18: Linux work 4.4.0-57-generic #78-Ubu<br />
Description:<br />
<br />
Hi. I try to do next math:<br />
<br />
select extract( month from justify_days( timestamp '<span><span>2016-01-31</span></span>' +interval '1<br />
month' -timestamp '<span><span>2016-01-31</span></span>') );<br />
 date_part<br />
-----------<br />
         0<br />
(1 row)<br />
<br />
I expect `1` but get `0`. But here everything is right:<br />
<br />
&gt;Adjust interval so 30-day time periods are represented as months<br />
<br />
<a href="https://www.postgresql.org/docs/9.6/static/functions-datetime.html" rel="noreferrer" target="_blank">https://www.postgresql.org/doc<wbr />s/9.6/static/functions-datetim<wbr />e.html</a><br />
<br />
But with ability to setup justify date the math will be more sharp.<br />
<br />
Please implement next feature:<br />
<br />
select extract( month from justify_days( timestamp '<span><span>2016-01-31</span></span>' +interval '1<br />
month' -timestamp '<span><span>2016-01-31</span></span>'), timestamp '<span><span>2016-01-31</span></span>' );<br />
 date_part<br />
-----------<br />
         1<br />
(1 row)<br />
<br />
This is useful when I try to calculate how much month are left between<br />
service start and end dates.<br /></blockquote><div><br /></div><div>This is not the bug, so pgsql-hackers, pgsql-general are better places for this discussion <br /></div><div><br /></div><div>I am thinking so your request has sense, and should be registered in ToDo list <a href="https://wiki.postgresql.org/wiki/Todo" target="_blank">https://wiki.postgresql.org/<wbr />wiki/Todo</a></div><div><br /></div><div>You can try to connect people from PostgreSQL Pro company for implementation.</div><div><br /></div><div>Regards</div><div><br /></div><div>Pavel</div><div><br /></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">
<br />
Thank you.<br />
<span><font color="#888888"><br />
<br />
--<br />
Sent via pgsql-bugs mailing list (<a href="mailto:pgsql-bugs(at)postgresql(dot)org" target="_blank">pgsql-bugs(at)postgresql(dot)org</a>)<br />
To make changes to your subscription:<br />
<a href="http://www.postgresql.org/mailpref/pgsql-bugs" rel="noreferrer" target="_blank">http://www.postgresql.org/mail<wbr />pref/pgsql-bugs</a><br />
</font></span></blockquote></div><br /></div></div></div>
</div><div><br /></div></div></div><div>-------- Конец пересылаемого сообщения --------</div>

</blockquote></div><br /></div>
</blockquote>

Attachment Content-Type Size
unknown_filename text/html 5.8 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message gdr 2017-10-13 09:10:28 BUG #14851: Systemd kills long-running recovery
Previous Message Michael Paquier 2017-10-13 04:29:32 Re: BUG #14849: jsonb_build_object doesn't like VARIADIC calls very much

Browse pgsql-general by date

  From Date Subject
Next Message Benoit Lobréau 2017-10-13 08:25:42 Re: Index corruption & broken clog
Previous Message Laurenz Albe 2017-10-13 07:55:31 Re: Index corruption & broken clog

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2017-10-13 08:13:47 Re: Aggregate transition state merging vs. hypothetical set functions
Previous Message David Rowley 2017-10-13 07:43:45 Re: Partition-wise aggregation/grouping