<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>a.muse: Something like an SQL Paradox</title>
    <link>http://www.jessirae.com/blog/articles/2010/08/29/russells-paradox-and-sql</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Something like an SQL Paradox</title>
      <description>&lt;p&gt;I love &lt;a href="http://www.jessirae.com/blog/articles/2009/09/05/propositional-attitudes-substitution-into-intensional-contexts-and-web-browsers"&gt;philosophical problems translated into computer programs&lt;/a&gt;.  And while reading &lt;a href="http://www.amazon.com/gp/product/0596009763?ie=UTF8&amp;#38;tag=classroommovi-20&amp;#38;linkCode=as2&amp;#38;camp=1789&amp;#38;creative=390957&amp;#38;creativeASIN=0596009763"&gt;&lt;span class="caps"&gt;SQL&lt;/span&gt; Cookbook&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=classroommovi-20&amp;#38;l=as2&amp;#38;o=1&amp;#38;a=0596009763" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;, I thought I had come across another&amp;#8212;a form of &lt;a href="http://plato.stanford.edu/entries/russell-paradox/"&gt;Russell&amp;#8217;s Paradox&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;Russell&amp;#8217;s Paradox: a Review&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;You probably remember from logic class that Russell&amp;#8217;s Paradox pointed out something very disturbing about naive set theory, namely that it is unclear whether or not the set of all sets not members of themselves are members of themselves.   Or maybe you simply remember something about Barbers who shave only men who don&amp;#8217;t shave themselves.&lt;/p&gt;


	&lt;p&gt;Oh, yeah!!! How does that go again?&lt;/p&gt;


Imagine a town, Russelltown, where there is a barber who 
	&lt;ol&gt;
	&lt;li&gt;shaves all those men who don&amp;#8217;t shave themselves, and &lt;/li&gt;
		&lt;li&gt;doesn&amp;#8217;t shave any man who does shave himself.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Does the Barber of Russelltown shave himself?&lt;/p&gt;


	&lt;p&gt;By 1, the Barber has to shave himself, but by 2, the Barber cannot shave himself.&lt;/p&gt;


	&lt;p&gt;So, it would seem that Russelltown has a barber who is not a man&amp;#8212;an untenable solution.  Where did we go wrong?  Something must be wrong with our logic.&lt;/p&gt;


	&lt;p&gt;The general thought is that something is wrong with our axiomatic system.&lt;/p&gt;


	&lt;p&gt;&lt;em&gt;&lt;span class="caps"&gt;SQL&lt;/span&gt; Groups as Sets&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;In &lt;a href="http://www.amazon.com/gp/product/0596009763?ie=UTF8&amp;#38;tag=classroommovi-20&amp;#38;linkCode=as2&amp;#38;camp=1789&amp;#38;creative=390957&amp;#38;creativeASIN=0596009763"&gt;&lt;span class="caps"&gt;SQL&lt;/span&gt; Cookbook&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=classroommovi-20&amp;#38;l=as2&amp;#38;o=1&amp;#38;a=0596009763" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;, the author notes that a paradox arises for &lt;span class="caps"&gt;SQL&lt;/span&gt; groups.&lt;/p&gt;


	&lt;p&gt;What is a &lt;span class="caps"&gt;SQL&lt;/span&gt; group?  &lt;span class="caps"&gt;A SQL&lt;/span&gt; group is a non-empty, distinct set.  If you think about any &lt;span class="caps"&gt;SQL&lt;/span&gt; query that uses group by, this should be self evident.  &lt;span class="caps"&gt;SQL&lt;/span&gt; groups can&amp;#8217;t be empty otherwise it doesn&amp;#8217;t really make much sense to call it a group&amp;#8212;any nothing could be a group if empty groups are groups.  &lt;span class="caps"&gt;SQL&lt;/span&gt; groups must be distinct otherwise we would say that our the database has not identified two sets of rows as similar.&lt;/p&gt;


The real problem arises for &lt;span class="caps"&gt;SQL&lt;/span&gt; groups when you consider the two facts about &lt;span class="caps"&gt;SQL&lt;/span&gt; groups in conjunction:
	&lt;ol&gt;
	&lt;li&gt;An &lt;span class="caps"&gt;SQL&lt;/span&gt; group can by definition not be empty.  For instance, the aggregate function, &lt;span class="caps"&gt;COUNT&lt;/span&gt; returns a value &amp;gt;= 1.  So, by definition, groups must have at least one member.&lt;/li&gt;
		&lt;li&gt;&lt;span class="caps"&gt;SQL&lt;/span&gt; groups are syntactically promiscuous. To keep the &lt;span class="caps"&gt;SQL&lt;/span&gt; language flexible, &lt;span class="caps"&gt;NULL&lt;/span&gt; is a valid component of a &lt;span class="caps"&gt;SQL&lt;/span&gt; group by clause; however, NULLs are ignored by the group by function.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;By 1, &lt;span class="caps"&gt;SQL&lt;/span&gt; groups cannot be empty, but by 2, &lt;span class="caps"&gt;SQL&lt;/span&gt; groups must be empty.  Let&amp;#8217;s take a closer look&amp;#8230;.&lt;/p&gt;


	&lt;p&gt;Consider the following table:&lt;/p&gt;


&lt;code&gt;
select * from femaleLogicians
&lt;/code&gt;

	&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;br /&gt;
penelope maddy&lt;br /&gt;
ruth barcan marcus&lt;br /&gt;
susan haack&lt;/p&gt;


	&lt;p&gt;Consider that we insert several NULLs into the table like this&amp;#8230;&lt;/p&gt;


&lt;code&gt;
 insert into femaleLogicians values (NULL);
&lt;/code&gt;
&lt;br /&gt;
&lt;code&gt;
 insert into femaleLogicians values (NULL);
&lt;/code&gt;
&lt;br /&gt;
&lt;code&gt;
 insert into femaleLogicians values (NULL)
&lt;/code&gt;

	&lt;p&gt;Given this table and the two facts above, what would you expect the following query to return?&lt;/p&gt;


&lt;code&gt;
select coalesce(name, 'NULL') as name, 
&lt;/code&gt;
&lt;br /&gt;
&lt;code&gt;
count(name) from femaleLogicians
&lt;/code&gt;
&lt;br /&gt;
&lt;code&gt;
group by name;
&lt;/code&gt;

	&lt;p&gt;The query would actually return something like this&amp;#8230;&lt;/p&gt;


	&lt;table&gt;
		&lt;tr&gt;
			&lt;th&gt;name &lt;/th&gt;
			&lt;th&gt;count(name) &lt;/th&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; penelope maddy     &lt;/td&gt;
			&lt;td&gt; 1 &lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;




	&lt;table&gt;
		&lt;tr&gt;
			&lt;td&gt; ruth barcan marcus &lt;/td&gt;
			&lt;td&gt; 1 &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; susan haack &lt;/td&gt;
			&lt;td&gt; 1 &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; NULL &lt;/td&gt;
			&lt;td&gt; 0 &lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;




	&lt;p&gt;This difficulty doesn&amp;#8217;t arise by the definition of a &lt;span class="caps"&gt;SQL&lt;/span&gt; group alone; it arises by the definition of a &lt;span class="caps"&gt;SQL&lt;/span&gt; group &lt;em&gt;and&lt;/em&gt; through the requirement that &lt;span class="caps"&gt;NULL&lt;/span&gt; values are valid &lt;span class="caps"&gt;SQL&lt;/span&gt; group components.  Pretty cool, huh!!  I&amp;#8217;ll leave the work around solution as an exercise for the reader.&lt;/p&gt;


	&lt;p&gt;So, this &lt;span class="caps"&gt;SQL&lt;/span&gt; group &amp;#8220;paradox&amp;#8221; isn&amp;#8217;t Russell&amp;#8217;s paradox, but the similarity between a &lt;span class="caps"&gt;SQL&lt;/span&gt; group and a set makes one wonder whether it would be possible to create a group of all groups that do not contain themselves in &lt;span class="caps"&gt;SQL&lt;/span&gt;.  I don&amp;#8217;t believe syntatically something like that won&amp;#8217;t work, but supposed your could rewrite the &lt;span class="caps"&gt;ISO SQL&lt;/span&gt; standard to accept such a syntax.  Could you, with or without &lt;span class="caps"&gt;SQL&lt;/span&gt;, implement Russell&amp;#8217;s paradox as a computer program?  At very least, it appears that the problem can (like the &lt;a href="http://www.jessirae.com/blog/articles/2009/09/05/propositional-attitudes-substitution-into-intensional-contexts-and-web-browsers"&gt;problem of substitution into intensional contexts&lt;/a&gt;) be implemented using web pages in some way&amp;#8230; maybe that will have to be fleshed out in another post.&lt;/p&gt;
</description>
      <pubDate>Sun, 29 Aug 2010 09:46:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:c5efa07a-ec5d-41da-b2bd-2de9ffc3bc99</guid>
      <author>Jessica</author>
      <link>http://www.jessirae.com/blog/articles/2010/08/29/russells-paradox-and-sql</link>
      <category>technology</category>
      <category>sql</category>
      <category>paradox</category>
      <category>russell</category>
      <category>philosophy</category>
      <trackback:ping>http://www.jessirae.com/blog/articles/trackback/12850</trackback:ping>
    </item>
  </channel>
</rss>

