<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for RightBrain Networks</title>
	<atom:link href="http://www.rightbrainnetworks.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rightbrainnetworks.com</link>
	<description></description>
	<lastBuildDate>Thu, 11 Aug 2011 13:49:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comment on Base36 Conversion in PostgreSQL by Jamie</title>
		<link>http://www.rightbrainnetworks.com/blog/base36-conversion-in-postgresql/comment-page-1/#comment-742</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Thu, 11 Aug 2011 13:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=148#comment-742</guid>
		<description>Thanks for the feedback!</description>
		<content:encoded><![CDATA[<p>Thanks for the feedback!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Base36 Conversion in PostgreSQL by Robert</title>
		<link>http://www.rightbrainnetworks.com/blog/base36-conversion-in-postgresql/comment-page-1/#comment-741</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Thu, 11 Aug 2011 13:11:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=148#comment-741</guid>
		<description>Another limitation of this code is - it supports only half of possbible bigint values (only positive ones). When ret overflows - function returns exception.</description>
		<content:encoded><![CDATA[<p>Another limitation of this code is &#8211; it supports only half of possbible bigint values (only positive ones). When ret overflows &#8211; function returns exception.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Base36 Conversion in PostgreSQL by Robert</title>
		<link>http://www.rightbrainnetworks.com/blog/base36-conversion-in-postgresql/comment-page-1/#comment-740</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Wed, 10 Aug 2011 10:52:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=148#comment-740</guid>
		<description>Your base36_decode contains bug in string:

ret := ret + (val * (36 ^ i));

For large numbers (for example,
select * from base36_decode(&#039;324adc6a6ds&#039;));

it returns
ERROR:  invalid input syntax for integer: &quot;1.11836923491136e+16&quot;
CONTEXT:  PL/pgSQL function &quot;base36_decode&quot; line 17 at assignment

Mentioned string must be fixed as follows:
ret := ret + (val * (36 ^ i))::bigint;

After that all works ok, thanks for sharing your code.</description>
		<content:encoded><![CDATA[<p>Your base36_decode contains bug in string:</p>
<p>ret := ret + (val * (36 ^ i));</p>
<p>For large numbers (for example,<br />
select * from base36_decode(&#8217;324adc6a6ds&#8217;));</p>
<p>it returns<br />
ERROR:  invalid input syntax for integer: &#8220;1.11836923491136e+16&#8243;<br />
CONTEXT:  PL/pgSQL function &#8220;base36_decode&#8221; line 17 at assignment</p>
<p>Mentioned string must be fixed as follows:<br />
ret := ret + (val * (36 ^ i))::bigint;</p>
<p>After that all works ok, thanks for sharing your code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Base36 Conversion in PostgreSQL by PK</title>
		<link>http://www.rightbrainnetworks.com/blog/base36-conversion-in-postgresql/comment-page-1/#comment-734</link>
		<dc:creator>PK</dc:creator>
		<pubDate>Sat, 28 May 2011 16:22:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=148#comment-734</guid>
		<description>Would you have a C equivalent of this? Doing this in pl/pgsql is going to be a major hit. 

Thanks!</description>
		<content:encoded><![CDATA[<p>Would you have a C equivalent of this? Doing this in pl/pgsql is going to be a major hit. </p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Base36 Conversion in PostgreSQL by Jamie</title>
		<link>http://www.rightbrainnetworks.com/blog/base36-conversion-in-postgresql/comment-page-1/#comment-696</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Wed, 04 Aug 2010 16:52:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=148#comment-696</guid>
		<description>Certainly.  You may use it in anyway you wish; no attribution is necessary.  Though, as I mentioned in the original posting, you may want to test the performance of the functions or maybe even reconsider whether this is a task that should be done within the DB.</description>
		<content:encoded><![CDATA[<p>Certainly.  You may use it in anyway you wish; no attribution is necessary.  Though, as I mentioned in the original posting, you may want to test the performance of the functions or maybe even reconsider whether this is a task that should be done within the DB.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Base36 Conversion in PostgreSQL by P</title>
		<link>http://www.rightbrainnetworks.com/blog/base36-conversion-in-postgresql/comment-page-1/#comment-695</link>
		<dc:creator>P</dc:creator>
		<pubDate>Tue, 03 Aug 2010 22:40:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=148#comment-695</guid>
		<description>May I use these in a commercial project? If so may I make changes if attribution is provided?</description>
		<content:encoded><![CDATA[<p>May I use these in a commercial project? If so may I make changes if attribution is provided?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Base36 Conversion in PostgreSQL by P</title>
		<link>http://www.rightbrainnetworks.com/blog/base36-conversion-in-postgresql/comment-page-1/#comment-694</link>
		<dc:creator>P</dc:creator>
		<pubDate>Tue, 03 Aug 2010 22:39:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=148#comment-694</guid>
		<description>May I use this in some commercial work I&#039;ve been doing? If so may I make changes if attribution is given?</description>
		<content:encoded><![CDATA[<p>May I use this in some commercial work I&#8217;ve been doing? If so may I make changes if attribution is given?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Rounding datetimes and timestamps in PostgreSQL by Jamie</title>
		<link>http://www.rightbrainnetworks.com/blog/rounding-datetimes-and-timestamps-in-postgresql/comment-page-1/#comment-691</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Tue, 29 Jun 2010 13:34:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=163#comment-691</guid>
		<description>Interesting solution... Thanks for taking the time to write it up and post!</description>
		<content:encoded><![CDATA[<p>Interesting solution&#8230; Thanks for taking the time to write it up and post!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Rounding datetimes and timestamps in PostgreSQL by Anonymous</title>
		<link>http://www.rightbrainnetworks.com/blog/rounding-datetimes-and-timestamps-in-postgresql/comment-page-1/#comment-690</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 29 Jun 2010 08:42:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=163#comment-690</guid>
		<description>Hi,

You may like this solution also...

== Solution #1

You could build a 60 rows table with two columns : &quot;minute&quot; and &quot;nearest&quot;. Those 60 rows are pre-computed. Make &quot;minute&quot; the PK. 

By joining, you can get the nearest increment, and then you can compute back the rounded timestamp.

create table report.nearest
(
	&quot;minute&quot; integer,
	nearest time,
	constraint nearest_pk primary key (&quot;minute&quot;)
) ;

--
-- To be done once, when application is deployed
--

insert into report.nearest values (0, time &#039;00:00&#039;) ;
insert into report.nearest values (1, time &#039;00:00&#039;) ;
...
insert into report.nearest values (14, time &#039;00:00&#039;) ;
insert into report.nearest values (15, time &#039;00:15&#039;) ;
insert into report.nearest values (16, time &#039;00:16&#039;) ;
...

create table report.billing
(
	tstamp   timestamp,
	whatever integer
) ;

insert into report.billing values(timestamp &#039;2001-02-16 20:14:12&#039;, 1) ;
insert into report.billing values(timestamp &#039;2001-02-16 20:15:34&#039;, 2) ;

select
	B.tstamp,
	N.nearest,
	date_trunc(&#039;hour&#039;, B.tstamp) + N.nearest as rounded
from
	report.billing B,
	report.nearest N
where
	extract(minute from B.tstamp) = N.&quot;minute&quot; ;

Results are :

 TSTAMP              NEAREST  ROUNDED
 ------------------- -------- -------------------
 2001-02-16 20:14:12 00:00:00 2001-02-16 20:00:00
 2001-02-16 20:15:34 00:15:00 2001-02-16 20:15:00

The underlying principle is simple: you can tradeoff storage for computing power (and way back). Here, storage is table report.nearest and computing power is your round_timestamp function.

Btw, in database terminology, I guess &quot;nearest&quot; is a dimension table and &quot;billing&quot; is the fact table.

I don&#039;t know if this solution &quot;is the most elegant&quot; as you state but it is &quot;full SQL&quot;: usually, this is to be prefered because database engines are better at &quot;crunching&quot; sets of data and optmizing SQL requests rather than running procedural code.

== Solution #2

If you manage lots of billing records within a batch process (I mean 100K or millions rows maybe), you may consider to compute more data ahead of the batch time window.

Maybe extract(minute from B.tstamp) could be precomputed in a new column when the billing record is created ? The effect on whole performance of the application could be good ... or worse, it depends on the environment and must be validated.

Note: this denormalizes the data model to get better performance and should be documented.


Hope this helps.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>You may like this solution also&#8230;</p>
<p>== Solution #1</p>
<p>You could build a 60 rows table with two columns : &#8220;minute&#8221; and &#8220;nearest&#8221;. Those 60 rows are pre-computed. Make &#8220;minute&#8221; the PK. </p>
<p>By joining, you can get the nearest increment, and then you can compute back the rounded timestamp.</p>
<p>create table report.nearest<br />
(<br />
	&#8220;minute&#8221; integer,<br />
	nearest time,<br />
	constraint nearest_pk primary key (&#8220;minute&#8221;)<br />
) ;</p>
<p>&#8211;<br />
&#8211; To be done once, when application is deployed<br />
&#8211;</p>
<p>insert into report.nearest values (0, time &#8217;00:00&#8242;) ;<br />
insert into report.nearest values (1, time &#8217;00:00&#8242;) ;<br />
&#8230;<br />
insert into report.nearest values (14, time &#8217;00:00&#8242;) ;<br />
insert into report.nearest values (15, time &#8217;00:15&#8242;) ;<br />
insert into report.nearest values (16, time &#8217;00:16&#8242;) ;<br />
&#8230;</p>
<p>create table report.billing<br />
(<br />
	tstamp   timestamp,<br />
	whatever integer<br />
) ;</p>
<p>insert into report.billing values(timestamp &#8217;2001-02-16 20:14:12&#8242;, 1) ;<br />
insert into report.billing values(timestamp &#8217;2001-02-16 20:15:34&#8242;, 2) ;</p>
<p>select<br />
	B.tstamp,<br />
	N.nearest,<br />
	date_trunc(&#8216;hour&#8217;, B.tstamp) + N.nearest as rounded<br />
from<br />
	report.billing B,<br />
	report.nearest N<br />
where<br />
	extract(minute from B.tstamp) = N.&#8221;minute&#8221; ;</p>
<p>Results are :</p>
<p> TSTAMP              NEAREST  ROUNDED<br />
 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
 2001-02-16 20:14:12 00:00:00 2001-02-16 20:00:00<br />
 2001-02-16 20:15:34 00:15:00 2001-02-16 20:15:00</p>
<p>The underlying principle is simple: you can tradeoff storage for computing power (and way back). Here, storage is table report.nearest and computing power is your round_timestamp function.</p>
<p>Btw, in database terminology, I guess &#8220;nearest&#8221; is a dimension table and &#8220;billing&#8221; is the fact table.</p>
<p>I don&#8217;t know if this solution &#8220;is the most elegant&#8221; as you state but it is &#8220;full SQL&#8221;: usually, this is to be prefered because database engines are better at &#8220;crunching&#8221; sets of data and optmizing SQL requests rather than running procedural code.</p>
<p>== Solution #2</p>
<p>If you manage lots of billing records within a batch process (I mean 100K or millions rows maybe), you may consider to compute more data ahead of the batch time window.</p>
<p>Maybe extract(minute from B.tstamp) could be precomputed in a new column when the billing record is created ? The effect on whole performance of the application could be good &#8230; or worse, it depends on the environment and must be validated.</p>
<p>Note: this denormalizes the data model to get better performance and should be documented.</p>
<p>Hope this helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Adding a &#8220;disable&#8221; feature to the script.aculo.us Ajax.Autocompleter by anyone</title>
		<link>http://www.rightbrainnetworks.com/blog/adding-a-disable-feature-to-the-scriptalicious-ajax-autocompleter/comment-page-1/#comment-688</link>
		<dc:creator>anyone</dc:creator>
		<pubDate>Fri, 28 May 2010 03:29:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.rightbrainnetworks.com/?p=8#comment-688</guid>
		<description>couldn&#039;t you use the standard autocompleter and just change the options.minChars value to more than the maxlength of the field when you want to disable it?</description>
		<content:encoded><![CDATA[<p>couldn&#8217;t you use the standard autocompleter and just change the options.minChars value to more than the maxlength of the field when you want to disable it?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

