<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>wonkablog &#187; Databases</title>
	<atom:link href="http://wonkabar.org/category/computers/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://wonkabar.org</link>
	<description>linux, databases, cartoons and cornflakes</description>
	<lastBuildDate>Tue, 27 Jul 2010 21:25:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>standardizing on booleans in mysql</title>
		<link>http://wonkabar.org/2009/04/08/standardizing-on-booleans-in-mysql/</link>
		<comments>http://wonkabar.org/2009/04/08/standardizing-on-booleans-in-mysql/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 15:45:46 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/?p=789</guid>
		<description><![CDATA[Okay, so here's a question I would normally pose to a mailing list, but since my email setups are so jacked up at the moment, there really isn't a good way I could subscribe and ask one, so I'll just post this to my blog instead and hope for some input.  Not that I don't [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so here's a question I would normally pose to a mailing list, but since my email setups are so jacked up at the moment, there really isn't a good way I could subscribe and ask one, so I'll just post this to my blog instead and hope for some input.  Not that I don't have anything against mailing lists, mind you, it's just that I don't like setting up an email account and subscribing when I post maybe three times a year, and lurk and read the rest of the time.</p>
<p>Anyway.  At work, I was looking at cleaning up one database table of a project I'm working on, and I noticed that we have three ways that we are storing boolean values in the table:</p>
<ul>
<li>unsigned tinyint, which presumably would only be set to 0 or 1</li>
<li>char(1), which also should be set to 0 or 1</li>
<li>enum('y',n')</li>
</ul>
<p>I, personally, always prefer the tinyint route.  Not really for a technical reason so much as a historical one ... it's just kind of the first one I picked.   What I would really like is if MySQL had a *real* boolean type field similar to postgresql, where the values can be TRUE, FALSE, 't' or 'f'.  It makes things so much easier.</p>
<p>MySQL will accept BOOL as a column type when creating a column, but it's implementation is a bit jacked in my opinion.  It creates an unsigned tinyint column, with null attributes.  That just gives a huge range of possible options, and doesn't really come that close to a binary option set at all.</p>
<blockquote><p>mysql&gt; create table test (steve bool);<br />
Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql&gt; desc test;<br />
+-------+------------+------+-----+---------+-------+<br />
| Field | Type       | Null | Key | Default | Extra |<br />
+-------+------------+------+-----+---------+-------+<br />
| steve | tinyint(1) | YES  |     | NULL    |       |<br />
+-------+------------+------+-----+---------+-------+<br />
1 row in set (0.00 sec)</p></blockquote>
<p>I did a bit of research, since enum seems now like the most reasonable option -- it limits you to a strict sub set of options.  The only question I have is, how well would that index?  Would it be faster scanning the table for enums or integers?  That's where I'm not sure.  It turns out that an enum that stores up to 255 values will only use 1 byte (assuming I'm intrepreting this MySQL reference book correctly).  A tiny integer uses the same size.  So it seems like they should both be pretty optimal, but I dunno.</p>
<p>Any thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2009/04/08/standardizing-on-booleans-in-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>mysql ordering by string with possible blank entries</title>
		<link>http://wonkabar.org/2008/11/15/mysql-ordering-by-string-with-possible-blank-entries/</link>
		<comments>http://wonkabar.org/2008/11/15/mysql-ordering-by-string-with-possible-blank-entries/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 17:31:09 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/?p=527</guid>
		<description><![CDATA[I just found a workaround to something I've always preferred to do in SQL.  I'm using MySQL 5 at work, and I had a query where I would order the entries by a column that is a varchar.  Since there was the possibility for this column to be blank, it would display all [...]]]></description>
			<content:encoded><![CDATA[<p>I just found a workaround to something I've always preferred to do in SQL.  I'm using MySQL 5 at work, and I had a query where I would order the entries by a column that is a varchar.  Since there was the possibility for this column to be blank, it would display all rows with a blank entry first, and then alphabetically from there.</p>
<p>So, the order would be something like: ' ', ' ', '1', '2', '3', 'A', 'B', 'C'.</p>
<p>What I really wanted was to display the blank ones last, since I wasn't interested in those.  I poked through <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html">the string functions available</a> to see if I could conjure up a hack, and <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_ascii">ASCII</a> works great, as it fetches the ASCII numeral of the first character in the string.  And, if the string is empty, it will return a zero.  And that's all I needed, was a binary flag to order by first.</p>
<p>Here's a sample query then:</p>
<p style="padding-left: 30px;">SELECT string FROM table ORDER BY ! ASCII(string), string;</p>
<p>And the result would be: '1', '2', '3', 'A', 'B', 'C', ' ', ' '.</p>
<p>Perfect. <img src='http://wonkabar.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2008/11/15/mysql-ordering-by-string-with-possible-blank-entries/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>postgres and mysql comparison paper</title>
		<link>http://wonkabar.org/2008/08/06/postgres-and-mysql-comparison-paper/</link>
		<comments>http://wonkabar.org/2008/08/06/postgres-and-mysql-comparison-paper/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 14:42:06 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/archives/454</guid>
		<description><![CDATA[I've been job hunting, and while my dream job would be somewhere that uses PostgreSQL, I am having an extremely hard time finding anyone that uses it.  So, I think my chances might be better actually getting a company to convert to using it instead.  In doing that, I've started outlining a draft [...]]]></description>
			<content:encoded><![CDATA[<p>I've been job hunting, and while my dream job would be somewhere that uses PostgreSQL, I am having an extremely hard time finding anyone that uses it.  So, I think my chances might be better actually getting a company to convert to using it instead.  In doing that, I've started outlining a draft of a paper that I can present to both lead programmers, database administrators, and management on the pros of using PostgreSQL over MySQL.   If anyone has some ideas that I could add in, I would appreciate it.</p>
<p>Here's the general principles I already plan on covering: foreign key support, data types, transactions, shell interface, ANSI SQL support, table types, general features, history, licensing, abstraction layers (using PHP).</p>
<p>Also, and I don't mean to sound like I'm spreading FUD, but it occurred to me this morning that I've never heard anyone say that MySQL is better than PostgreSQL.</p>
<p>Anyway, ideas welcome.  I'll post my progress as I get the paper put together.  This is something I've been meaning to do for a long time.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2008/08/06/postgres-and-mysql-comparison-paper/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>prepared statements and stored procedures</title>
		<link>http://wonkabar.org/2008/03/23/prepared-statements-and-stored-procedures/</link>
		<comments>http://wonkabar.org/2008/03/23/prepared-statements-and-stored-procedures/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 22:48:37 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/archives/414</guid>
		<description><![CDATA[I'm still working on cleaning up the import scripts for GPNL, and I'm going to have to start using PHP's PDO database layer to connect to an SQLite3 database at one point.
I haven't used it yet, but I had heard it was coming in PHP 5 for a while.  Personally, I've always used PEAR::DB [...]]]></description>
			<content:encoded><![CDATA[<p>I'm still working on cleaning up the import scripts for GPNL, and I'm going to have to start using PHP's PDO database layer to connect to an SQLite3 database at one point.</p>
<p>I haven't used it yet, but I had heard it was coming in PHP 5 for a while.  Personally, I've always used <a href="http://pear.php.net/package/DB">PEAR::DB</a> and was quite happy with that.</p>
<p>I'm still not sold on using the new layer anyway, but I figured I'd do some reading while I am getting ready to use it in this very small instance that I'm implementing.</p>
<p>On the docs page, I found a great summary of why prepared statements and stored procedures are handy and helpful.  In short: they save you time for queries you have to repeat a lot, by pre-compiling the preparation that is common to all the queries, so that the database is really only processing the new data, and thus using less resources.</p>
<p>Prepared statements I haven't played with much before until a few weeks ago, but I've slowly started using them in my import scripts.  Performance-wise, I've only seen about a 15 to 20 percent speed increase.  The thing I like the most about them, though, is that I don't have to escape my strings anymore.  That's a nice little advantage I can live with.</p>
<p>Anyway, <a href="http://us2.php.net/manual/en/ref.pdo.php">php.net's PDO documentation page</a> has a nice writeup as well, and instead of trying to summarize it myself any more, I'll just quote it verbatim:</p>
<p class="para">      Many of the more mature databases support the concept of prepared      statements.  What are they? You can think of them as a kind of compiled      template for the SQL that you want to run, that can be customized using      variable parameters.  Prepared statements offer two major benefits:</p>
<ul class="itemizedlist">
<li class="listitem">       <span class="simpara">        The query only needs to be parsed (or prepared) once, but can be        executed multiple times with the same or different parameters. When the        query is prepared, the database will analyze, compile and optimize it's        plan for executing the query. For complex queries this process can take        up enough time that it will noticeably slow down your application if you        need to repeat the same query many times with different parameters. By        using a prepared statement you avoid repeating the        analyze/compile/optimize cycle. In short, prepared statements use fewer        resources and thus run faster.       </span></li>
<li class="listitem">       <span class="simpara">        The parameters to prepared statements don't need to be quoted; the        driver handles it for you. If your application exclusively uses        prepared statements, you can be sure that no SQL injection will occur.        (However, if you're still building up other parts of the query based on        untrusted input, you're still at risk).       </span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2008/03/23/prepared-statements-and-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nice mysql vs postgres summary</title>
		<link>http://wonkabar.org/2008/03/23/nice-mysql-vs-postgres-summary/</link>
		<comments>http://wonkabar.org/2008/03/23/nice-mysql-vs-postgres-summary/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 18:21:08 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/archives/413</guid>
		<description><![CDATA[I was googling for a postgresql image I could use when I found this page, a nice short summary on the differences between MySQL and PostgreSQL with an emphasis on development policy.
I should mention that I'm linking to it because I agree with the author and also because I'm biased towards PostgreSQL.  I prefer [...]]]></description>
			<content:encoded><![CDATA[<p>I was googling for a postgresql image I could use when I found <a href="http://www.teknico.net/devel/myvspg/index.en.html">this page</a>, a nice short summary on the differences between MySQL and PostgreSQL with an emphasis on development policy.</p>
<p>I should mention that I'm linking to it because I agree with the author and also because I'm biased towards PostgreSQL.  I prefer postgres not because of fanboyism, but because of experience and years of using both databases.</p>
<p>I was actually lucky enough to be trained to use PostgreSQL as the first database I ever used, and everything after that has never been able to duplicate its feature set.  Since my first tech job, I've worked with Access, MySQL, SQL Server 2000 and SQLite.</p>
<p>Anyway, I love postgres.  If you've never given it a chance, and you are looking for more advanced features, check it out.  It's all that and a box of girl scout cookies.  I tell you what.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2008/03/23/nice-mysql-vs-postgres-summary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>potential postgres schema for lds-scriptures 3.0</title>
		<link>http://wonkabar.org/2007/04/25/potential-postgres-schema-for-lds-scriptures-30/</link>
		<comments>http://wonkabar.org/2007/04/25/potential-postgres-schema-for-lds-scriptures-30/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 14:01:11 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Religion]]></category>

		<guid isPermaLink="false">http://wonkabar.org/archives/273</guid>
		<description><![CDATA[Well, that was fast.  I looked at the schema last night for the MDP Scriptures project, and started cleaning it up, and it went really quickly.  I've got a postgres dump all ready for review, and this is probably the configuration I'll use for the next release.
The major change was that I added [...]]]></description>
			<content:encoded><![CDATA[<p>Well, that was fast.  I looked at the schema last night for the <a href="http://scriptures.nephi.org/">MDP Scriptures</a> project, and started cleaning it up, and it went really quickly.  I've got a postgres dump all ready for review, and this is probably the configuration I'll use for the next release.</p>
<p>The major change was that I added a new table for the chapters.  It seems a little odd having the chapter number in a table all its own, but for a normalized database schema it makes perfect sense.  The only thing I don't like is now you have to INNER JOIN across four tables just to get all the information.  Most of the time you won't need anything but book + chapter + verse, which is only three tables.  I did create a sample view called view_verses which pulls them all together so you can easily run a select on some format like 'Gen 1:1'.  The thing I don't like is that even that view is CPU intensive, so I may have to look at changing some stuff around.</p>
<p>Aside from that basic view, I've decided I'm not going to put all my fun ideas for functions and views in the packaged release.  Instead, I'll just have them either as a separate release, or just post them on the website since I'm sure they will evolve.</p>
<p>One really cool thing about postgres that I love is that you can have overloaded functions.  I started playing with them a while back on this database, and came up with some cool concepts.  One idea I want to implement is being able to run a select statment using a between on two verses.  An example query would be: "SELECT * FROM view_verses WHERE verse_id BETWEEN verse('Gen.', 1, 5) AND verse('Genesis', 12); where the verse() function would be overloaded to take between one and three arguments: book, chapter and verse.</p>
<p>It's pretty cool all the stuff you can do with postgres, and that's definately where I'll be focusing my attention in getting the goodies done.</p>
<p>Anyway, if you want to download this test schema, its available <a href="http://spaceparanoids.org/nephi/scriptures_pgsql_070425.sql.zip">here</a>.  As always, <a href="/contact-me/">feedback</a> is welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2007/04/25/potential-postgres-schema-for-lds-scriptures-30/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>gentoo packages that need lovin&#8217;</title>
		<link>http://wonkabar.org/2006/11/27/gentoo-packages-that-need-lovin/</link>
		<comments>http://wonkabar.org/2006/11/27/gentoo-packages-that-need-lovin/#comments</comments>
		<pubDate>Mon, 27 Nov 2006 15:58:29 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Gentoo]]></category>

		<guid isPermaLink="false">http://wonkabar.org/archives/215</guid>
		<description><![CDATA[I mentioned not too long ago that I was working on getting portage details crammed into postgresql, and here is the end result.
GPNL is meant to be a QA tool for treecleaners to use, making it easier to find packages and ebuilds that ... well, need some lovin.
Though it's primarily intended for quality assurance, I've [...]]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://wonkabar.org/archives/202">mentioned</a> not too long ago that I was working on getting portage details crammed into postgresql, and <a href="http://spaceparanoids.org/gentoo/gpnl/">here</a> is the end result.</p>
<p><a href="http://spaceparanoids.org/gentoo/gpnl/">GPNL</a> is meant to be a QA tool for <a href="http://www.gentoo.org/proj/en/qa/treecleaners/">treecleaners</a> to use, making it easier to find packages and ebuilds that ... well, need some lovin.</p>
<p>Though it's primarily intended for quality assurance, I've written the frontend to be hopefully pretty generic so anyone can browse the portage tree and just see some interesting statistics all around.  There's still a lot more to be done on the website, but I think it's to a point right now where it's at least ready for some public consumption.</p>
<p>One thing I'm excited about is setting up the advanced search page, where you'll be able to run all kinds of funky queries.  I'm going to be adding some more QA checks as well, once I get some time.  Getting this much done though was quite a lot of work though, and I'm probably going to take a break and focus more on other things for a while.  However, if anyone has some reasonable feature requests, I'm all ears.</p>
<p>Oh, also the source code for the database schema and the import scripts is <a href="http://spaceparanoids.org/svn/gpnl/">available online</a>.  I'll setup SVN access and some documentation on the db layout sometime soon, not to mention how to get it working (short howto: emerge php, pkgcore, postgresql and portage-utils).</p>
<p>Also, a huge shout out to marienz and ferringb who put together <a href="http://dev.gentooexperimental.org/pkgcore-trac">pkgcore</a> and my little python scripts that made importing the data incredibly simple.  Thanks, guys. <img src='http://wonkabar.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/11/27/gentoo-packages-that-need-lovin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>death to sql server (part 4)</title>
		<link>http://wonkabar.org/2006/11/10/death-to-sql-server-part-4/</link>
		<comments>http://wonkabar.org/2006/11/10/death-to-sql-server-part-4/#comments</comments>
		<pubDate>Fri, 10 Nov 2006 18:52:46 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/archives/206</guid>
		<description><![CDATA[I've written about this before, but to rehash ... the date functions inside SQL server suck. What's really weird is that there's an undocumented way to retrieve out certain datetime formats, and even that is inconsistent in its numbering scheme.
The way to pull them out is by running "SELECT CONVERT(VARCHAR, GETDATE(), @x);" where @x is [...]]]></description>
			<content:encoded><![CDATA[<p>I've written about this <a href="http://wonkabar.org/archives/4">before</a>, but to rehash ... the date functions inside SQL server suck. What's really weird is that there's an undocumented way to retrieve out certain datetime formats, and even that is inconsistent in its numbering scheme.</p>
<p>The way to pull them out is by running "SELECT CONVERT(VARCHAR, GETDATE(), @x);" where @x is a positive integer. If you can find the right integer, you can save time and pull out something directly like '11-10-2006' as your variable.</p>
<p>One of the problems you'll run into though is that you can't just do 1 through $integer. Only some of them return something, and the ones that don't just throw an SQL error, so you get to hunt down which integers return something.</p>
<p>Well, digging for them manually once is something I don't want to repeat, so I wrote a query statement to pull out some of them. This could be a handy reference inside your database somewhere.</p>
<p><tt>DECLARE @x int;<br />
SET @x = 1;<br />
WHILE @x < 132 BEGIN<br />
IF @x > 0 AND (@x < 14 OR (@x > 20 AND @x &lt;25) OR (@x > 99 AND @x < 115) OR @x IN(126,130,131)) BEGIN<br />
SELECT @x, CONVERT(VARCHAR, GETDATE(), @x);<br />
END<br />
SELECT @x = (@x +1);</tt></tt><tt><br />
END</tt></p>
<p>Here's <a href="http://sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk">another online reference you can use. </a></p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/11/10/death-to-sql-server-part-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>postgresql functions</title>
		<link>http://wonkabar.org/2006/11/08/postgresql-functions/</link>
		<comments>http://wonkabar.org/2006/11/08/postgresql-functions/#comments</comments>
		<pubDate>Thu, 09 Nov 2006 04:41:04 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/archives/203</guid>
		<description><![CDATA[One thing I love about (advanced) databases is that you can write functions. They speed up the query time quite a bit, and you can do fun stuff like IF ... ELSE ... THEN statements.
In working on getting portage into postgres, part of the problem I'm trying to solve is find out where QA issues [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I love about (advanced) databases is that you can write functions. They speed up the query time quite a bit, and you can do fun stuff like IF ... ELSE ... THEN statements.</p>
<p>In working on getting portage into postgres, part of the problem I'm trying to solve is find out where QA issues are so they can be fixed. Unfortunately, in the early stages of my little script, it always assumes that the everything is working correctly across the board, so I'll write my queries assuming the foreign keys won't break. In reality, that doesn't happen, and I end up killing a transaction with hundreds of thousands of statements because there's 25 queries that break.</p>
<p>So, I had to write a postgres function to do the checking for me. This is going to be absolutely boring to those db gurus out there, but this is still slightly new to me, so I'm really enjoying it.</p>
<blockquote>
<pre class="code"><span class="keyword">DECLARE</span>
use_id <span class="keyword">integer</span>;
<span class="keyword">BEGIN</span>
<span class="keyword">SELECT</span> id <span class="keyword">FROM</span> use <span class="keyword">WHERE</span> <span class="keyword">name</span> = $2 <span class="keyword">AND</span>
(package <span class="keyword">IS</span> <span class="keyword">NULL</span> <span class="keyword">OR</span> package = $3) LIMIT 1 <span class="keyword">INTO</span> use_id;
IF use_id <span class="keyword">IS</span> <span class="keyword">NOT</span> <span class="keyword">NULL</span> <span class="keyword">THEN</span>
<span class="keyword">INSERT</span> <span class="keyword">INTO</span> ebuild_use (ebuild, use) <span class="keyword">VALUES</span> ($1, use_id);
<span class="keyword">RETURN</span> <span class="keyword">TRUE</span>;
<span class="keyword">ELSE</span>
<span class="keyword">RETURN</span> <span class="keyword">FALSE</span>;
<span class="keyword">END</span> IF;
<span class="keyword">END</span>;</pre>
</blockquote>
<p>A really simple function, I know. All it does is run a SELECT statement to see if my foreign key is going to break *before* running the INSERT statement. That way, I can continue on my happy way with my transaction, and at the same time, if I want to turn on 'qa mode' when inserting the data, I can check for a false return on the recordset, and know which ebuilds need attention.</p>
<p>Pretty cool stuff, I think. Also, for the record, pgaccess is a *great* little GUI tool to quickly and easily edit your functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/11/08/postgresql-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>portage in postgresql</title>
		<link>http://wonkabar.org/2006/11/08/portage-in-postgresql/</link>
		<comments>http://wonkabar.org/2006/11/08/portage-in-postgresql/#comments</comments>
		<pubDate>Wed, 08 Nov 2006 16:51:24 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Gentoo]]></category>

		<guid isPermaLink="false">http://wonkabar.org/archives/202</guid>
		<description><![CDATA[Well, I'm bored, so I figured I'd spill the beans on a project I've been keeping under wraps for a while.
I've been working on getting everything about the portage tree into postgresql so you can run all kinds of queries. What kinds of queries? How many ebuilds use eclass 'eutils' and USE flag 'alsa' and [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I'm bored, so I figured I'd spill the beans on a project I've been keeping under wraps for a while.</p>
<p>I've been working on getting everything about the portage tree into postgresql so you can run all kinds of queries. What kinds of queries? How many ebuilds use eclass 'eutils' and USE flag 'alsa' and are in 'video' herd and amd64 is masked but x86 isn't. That kind. Funky ones. <img src='http://wonkabar.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I must say, I really love postgresql even though I haven't been using it regularly for a long time, I'm quickly getting back into it. The simplicity, the standards, the power, the tools ... postgres has it all. Ahh, fanboyism.</p>
<p>Anyway, getting the details of the ebuilds was made incredibly easy thanks to marienz and ferringb and their work on <a href="http://dev.gentooexperimental.org/pkgcore-trac">pkgcore</a> (and a custom python script). After that, it was just a matter of parsing the information and setting up the schemas. My importer is written in PHP and the class to import / read the data is still in its slightly butt-ugly stage. It can use some cleaning up, for sure. The database layout is going to be where the real optimizations are though. I'm going to work on setting up some good views so it will be easy to query. Right now, here's the list of tables I have setup: arch, category, ebuild, ebuild_arch, ebuild_eclass, ebuild_homepage, ebuild_license, ebuild_use, eclass, eclass_use, herd, license, package and use. All of them can already be populated by the scripts except for eclass_use and herd. I haven't setup the dependency ones yet, though that'll be pretty simple too.</p>
<p>So there's my big announcement. Woots. I'm working on creating the SQL to import everything right now (which takes a long time), and once that's done, I'll throw up a db dump somewhere. There's still lots to be done, like finishing the import scripts and setting up some webpages to browse the tree, but it shouldn't be too hard. I'm definately over the worst of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/11/08/portage-in-postgresql/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>sql vs. sql</title>
		<link>http://wonkabar.org/2006/08/29/sql-vs-sql/</link>
		<comments>http://wonkabar.org/2006/08/29/sql-vs-sql/#comments</comments>
		<pubDate>Tue, 29 Aug 2006 15:29:37 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/?p=161</guid>
		<description><![CDATA[Once again, UPHPU has had a minor stir about which database is faster / better / stronger, PostgreSQL or MySQL. All fanboyism aside, who really cares?
You want to know the way to *really* speed up your database? Normalization is probably going to be the largest factor. After that, use views, stored procedures, indexes, transactions and [...]]]></description>
			<content:encoded><![CDATA[<p>Once again, UPHPU has had a minor stir about which database is faster / better / stronger, PostgreSQL or MySQL. All fanboyism aside, who really cares?</p>
<p>You want to know the way to *really* speed up your database? Normalization is probably going to be the largest factor. After that, use views, stored procedures, indexes, transactions and well-written queries, and your database is going to fly amazingly fast.</p>
<p>At work we have a large server we call "Zeus" because it is incredibly large. I won't even go into specs because you wouldn't believe me even if I told you. When I first started working here, the database running on it was incredibly slow. At first I blamed it all on the database software we are using (you can search my blog if you really wanna know which one it is. Hint: it's neither of the two mentioned above), but as we cleaned up the databases and tables by removing columns that were complete cruft and then doing everything I mentioned above, this puppy flies. In fact, our "dev" database, which is running on nothing more than an Athlon XP 1800+ runs just as fast as our beast-monster does.</p>
<p>That's how you get a fast database -- doing things the right way.  Who would have thought?</p>
<p>I have to apologize for the elitist feel of this post, but my point is this ... the only magic bullet in improving performance is going to be quality code and design. Just replacing your database with something else isn't going to make the speed fairy sprinkle your application with love.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/08/29/sql-vs-sql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>death to sql server (part 3)</title>
		<link>http://wonkabar.org/2006/06/22/death-to-sql-server-part-3/</link>
		<comments>http://wonkabar.org/2006/06/22/death-to-sql-server-part-3/#comments</comments>
		<pubDate>Thu, 22 Jun 2006 22:14:12 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/blog/?p=100</guid>
		<description><![CDATA[It's been a good while that I've ranted and raved against MS SQL Server.  I've actually found a few bugs since then, I just haven't documented them.
My beef this time around is that SQL Server 2000 doesn't have a TRIM() function. What's even more strange, is that they do have RTRIM and LTRIM functions. [...]]]></description>
			<content:encoded><![CDATA[<p>It's been a good while that I've <a href="http://wonkabar.org/blog/?p=4">ranted</a> and <a href="http://wonkabar.org/blog/?p=6">raved</a> against MS SQL Server.  I've actually found a few bugs since then, I just haven't documented them.</p>
<p>My beef this time around is that SQL Server 2000 doesn't have a TRIM() function. What's even more strange, is that they do have RTRIM and LTRIM functions. So, if you want to trim something you just run "UPDATE table SET foo = RTRIM(LTRIM(foo));" Brilliant!</p>
<p>Just another reason to love open source software -- you get incremental bug fixes <strong>and </strong>feature upgrades. This would have been fixed in any other database a long time ago, but since new features == new versions <a href="http://news.com.com/Microsoft+No+more+five-year+waits+for+SQL+Server/2100-1012_3-5955950.html">released every five years</a> with Microsoft, you're just plain stuck with what you paid for the first time around.</p>
<p>Yes, I know I'm trolling but really ... what defense do they have? I know I can create a UDF to do the work for me, but that's besides the point that I'm right and prefer laziness. Plus, it's one thing to say "MS suxxors" and another to point out why their software is so shoddy. And if there's one thing I enjoy doing, it's educating people on why they're wrong and <a href="http://www.gentoo.org/main/en/about.xml">Gentoo</a> is the extreme answer to everything.</p>
<p>Now go emerge <a href="http://www.postgresql.org/">postgres</a>, ya jerk.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/06/22/death-to-sql-server-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>what did I ever do without views?!</title>
		<link>http://wonkabar.org/2006/05/04/what-did-i-ever-do-without-views/</link>
		<comments>http://wonkabar.org/2006/05/04/what-did-i-ever-do-without-views/#comments</comments>
		<pubDate>Fri, 05 May 2006 00:44:56 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/blog/?p=54</guid>
		<description><![CDATA[There are some things in life that, once you get used to them ... there's just no going back. Things like underwear, Malt-O-Meal, Neverwinter Nights, and views.
At work we use databases much, much more than I ever have anywhere else. Because of that, I've been forced to stretch and learn more ways to do things [...]]]></description>
			<content:encoded><![CDATA[<p>There are some things in life that, once you get used to them ... there's just no going back. Things like underwear, Malt-O-Meal, Neverwinter Nights, and views.</p>
<p>At work we use databases much, much more than I ever have anywhere else. Because of that, I've been forced to stretch and learn more ways to do things efficiently because if things are going slow, we are losing $$$. All that's nice and good, but the part I'm enjoying as a developer is the convenience of that views, stored procedures and user-defined functions give me.</p>
<p>For instance, I'll use a recent example. We have three tables that we pull data from a lot, and I'm constantly doing INNER JOIN foo ON bar = poop across a lot of pages. Well, a view lets me take the most critical data of those three tables and lump them all into one subset. So now, I can just do 'SELECT * FROM view-la-la WHERE foo-poo-pah' and be done with it.</p>
<p>I really have no idea how I lasted so long without these great features. It's probably because I was stuck using that <em>other</em> open-source database that has said for years that those features weren't important. Well, that and because sometimes I won't try something new if I'm familiar with what I have. Until they stop selling my favorite flavor of Cream of Wheat at the store, and then I *have* to try something different. Mmm... Malt-O-Mealie.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/05/04/what-did-i-ever-do-without-views/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>database first impressions</title>
		<link>http://wonkabar.org/2006/04/16/34/</link>
		<comments>http://wonkabar.org/2006/04/16/34/#comments</comments>
		<pubDate>Mon, 17 Apr 2006 06:15:18 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/blog/?p=34</guid>
		<description><![CDATA[I've spent almost all day trying to get these free versions of large databases working. Well, that, and watching a good amount of Justice League. So far, I've yet to feel like I've made any good progress. Although that one battle with Lord Hades was pretty darn cool.
These new cartoons are a lot grittier than [...]]]></description>
			<content:encoded><![CDATA[<p>I've spent almost all day trying to get these free versions of large databases working. Well, that, and watching a good amount of <a href="http://www.amazon.com/gp/product/B000CSTK3S">Justice League</a>. So far, I've yet to feel like I've made any good progress. Although that one battle with Lord Hades was pretty darn cool.</p>
<p>These new cartoons are a lot grittier than even Batman: The Animated Series was. The animation isn't as sharp, though, but it is detailed in other places. It's a trade-off, I guess.</p>
<p>Anyway, here's my impressions so far:</p>
<p><strong>Oracle XE</strong></p>
<ul>
<li>Easy to install</li>
<li>A pain in the arse to connect, what the crap is TNS and SID variables I need to set?  I'm really lost.</li>
<li>The web interface is really slick.</li>
<li>The instant client installed without any issues on Gentoo (on both 32 and 64 bit installs, I dual boot).</li>
</ul>
<p><strong>SQL Server 2005 Express Edition</strong></p>
<ul>
<li>Just as easy to install</li>
<li>No cool frontends, no nothing.  It does come with a separate SQL script thing you can run in DOS (that's odd).</li>
<li>I can't figure out for the life of me how to connect with PHP, but I don't think it's going to be easy or possible, considering its so new. ODBC *might* work.</li>
<li>I'm not even sure if its accepting remote connections yet.  I can't even get an ODBC connection created.</li>
<li>I would be using the 2000 version, but I didn't find it til much later, and I've already got everything installed.</li>
<li>I would have found it much earlier if Microsoft didn't make it so freaking absolutely gouge-my-eyes-out incredibly hard to find. Naming the databases 2000 and 2005 doesn't help my search queries too much. Not that sql or server are really original either. Come up with some original names, guys, like ... "Relational Asinity" or something.</li>
</ul>
<p><strong>Firebird</strong></p>
<ul>
<li>I can't even get the thing started or figure out how to create a database.</li>
<li>I tried the web admin (ibwebadmin), and while it looks like a really cool app, see above.</li>
<li>Couldn't find any cool foss guis, so I gave up after searching for just a little bit to try the other ones.</li>
</ul>
<p><strong>IBM DB2</strong></p>
<ul>
<li>Just barely finished installing it, I'm feeling optimistic about this one.</li>
<li>Not too excited about installing RPMs on my Gentoo box just to get the PHP client working. Actually, I wouldn't mind if there was an ebuild. <img src='http://wonkabar.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<p>Granted, I'm reading very little documentation while I do this, other than the PHP website, and going as far as this will take me intuitively. I've spent most of my time on Oracle, and their website is really nice, and has a section just for PHP. I still can't get any connections working though.</p>
<p>One thing's for sure, it makes me love PostgreSQL even more than ever. And I used to think it was a pain to setup. Holy crap, its a cakewalk compared to these guys.</p>
<p>I think it's time for some more cartoons.  <a href="http://en.wikipedia.org/wiki/Green_Lantern">Green Lantern</a> is definately the man.  I think he's tougher than Superman.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/04/16/34/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>more lds-scriptures releases coming soon (hopefully)</title>
		<link>http://wonkabar.org/2006/04/13/more-lds-scriptures-releases-coming-soon-hopefully/</link>
		<comments>http://wonkabar.org/2006/04/13/more-lds-scriptures-releases-coming-soon-hopefully/#comments</comments>
		<pubDate>Fri, 14 Apr 2006 04:26:05 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://wonkabar.org/blog/?p=31</guid>
		<description><![CDATA[I'm sure I'm going to get into trouble by announcing something I *plan* on releasing, because then I might never get around to it ... but oh well, I felt like mentioning it.
I started working tonight on a SQL Server release of the lds-scriptures package. This one is actually going to have foreign keys, and [...]]]></description>
			<content:encoded><![CDATA[<p>I'm sure I'm going to get into trouble by announcing something I *plan* on releasing, because then I might never get around to it ... but oh well, I felt like mentioning it.</p>
<p>I started working tonight on a SQL Server release of the <a href="http://scriptures.nephi.org/">lds-scriptures</a> package. This one is actually going to have foreign keys, and maybe some views -- some of the big things that will be in the next point release for the other databases too.</p>
<p>Someday I'll have to get an eval version of Oracle and DB2 and maybe port it to those just for fun. <img src='http://wonkabar.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/04/13/more-lds-scriptures-releases-coming-soon-hopefully/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>death to sql server (part 2)</title>
		<link>http://wonkabar.org/2006/01/18/death-to-sql-server-part-2/</link>
		<comments>http://wonkabar.org/2006/01/18/death-to-sql-server-part-2/#comments</comments>
		<pubDate>Wed, 18 Jan 2006 14:40:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://flick/wordpress/?p=6</guid>
		<description><![CDATA[This one isn't a rant, just another head-scratching-that's-an-odd-thing-to-do kind of post.
One of the main scripts was running slow tonight that gets hit on a regular basis, and we couldn't figure out why.
So, we do what we do when we aren't sure what to do -- we reindex the table. That's the first general fix we [...]]]></description>
			<content:encoded><![CDATA[<p>This one isn't a rant, just another head-scratching-that's-an-odd-thing-to-do kind of post.</p>
<p>One of the main scripts was running slow tonight that gets hit on a regular basis, and we couldn't figure out why.</p>
<p>So, we do what we do when we aren't sure what to do -- we reindex the table. That's the first general fix we like to do. Turns out, that fixed it in this case, as well.</p>
<p>What had changed recently you might ask (and well so)?  We added a column to one of the database tables.</p>
<p>I guess that was too much of a strain for SQL Server.</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/01/18/death-to-sql-server-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>death to sql server (part 1)</title>
		<link>http://wonkabar.org/2006/01/17/death-to-sql-server-part-1/</link>
		<comments>http://wonkabar.org/2006/01/17/death-to-sql-server-part-1/#comments</comments>
		<pubDate>Tue, 17 Jan 2006 14:39:39 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://flick/wordpress/?p=4</guid>
		<description><![CDATA[Just for a background .. anyone who has talked to me for more than 30 seconds about databases knows that I hate Microsoft SQL Server with a passion. The real bonus is that it's not just an unfounded passion! I have proof of its inadequacy, which you'll see in this special 5,789-part story.
In today's adventure [...]]]></description>
			<content:encoded><![CDATA[<p>Just for a background .. anyone who has talked to me for more than 30 seconds about databases knows that I hate Microsoft SQL Server with a passion. The real bonus is that it's not just an unfounded passion! I have proof of its inadequacy, which you'll see in this special 5,789-part story.</p>
<p>In today's adventure our hero ran into a small problem -- he wanted to select year-month-day from the database in the format of (2006-01-17). Easy, you would think, until you've actually worked with the database first hand.</p>
<p>First, I tried selecting them all individuall and concatenating them together .. which worked, except that datepart() won't pad the zeroes (it would return 2006-1-17).</p>
<p>Next, I decided to write my own UDF (User Defined Function for the unwashed masses), which would set the variables, but I ran into another problem -- you can't run getdate() within a UDF. That's weird (translation: That's about the dumbest thing I've seen this databse do yet).</p>
<p>Actually, the last problem turned out for a small bonus, because with my new UDF I could just pass it in as a variable anyway. Sure it complicates the function a little bit, but it will work out in the end.</p>
<p>Speaking of which, here is the final SQL for the function:</p>
<p><tt>CREATE FUNCTION dateYMD(@getdate DATETIME) RETURNS VARCHAR(255) AS<br />
BEGIN<br />
DECLARE @year CHAR(4);<br />
DECLARE @month VARCHAR(2);<br />
DECLARE @day VARCHAR(2);<br />
DECLARE @date VARCHAR(255);</tt></p>
<p><tt>SET @year = YEAR(@getdate);<br />
SET @month = MONTH(@getdate);<br />
SET @day = DAY(@getdate);</tt></p>
<p><tt>IF LEN(@day) = 1 BEGIN SET @day = '0' + @day END<br />
IF LEN(@month) = 1 BEGIN SET @month = '0' + @month END</tt></p>
<p><tt>SET @date = @year + '-' + @month + '-' + @day;</tt></p>
<p><tt>RETURN @date;</tt></p>
<p><tt>END</tt></p>
<p>Then, the final blow. After about getting halfway through writing this one, I find that there's an undcoumented feature (I guess those Microsoft developers enjoy Easter Eggs just as much as I do) to do the same thing I was doing:</p>
<p><tt>SELECT CONVERT(VARCHAR, GETDATE(), 23);</tt></p>
<p>SQL Server: 1, Developer: 0</p>
]]></content:encoded>
			<wfw:commentRss>http://wonkabar.org/2006/01/17/death-to-sql-server-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
