<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Relational Database Theory</title>
	<atom:link href="http://vadimtropashko.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://vadimtropashko.wordpress.com</link>
	<description>with occasional pedestrian SQL topics</description>
	<lastBuildDate>Fri, 27 Jan 2012 17:23:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='vadimtropashko.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Relational Database Theory</title>
		<link>http://vadimtropashko.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://vadimtropashko.wordpress.com/osd.xml" title="Relational Database Theory" />
	<atom:link rel='hub' href='http://vadimtropashko.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Caclulating Entropy and Gini Index for a partitioned table</title>
		<link>http://vadimtropashko.wordpress.com/2012/01/26/caclulating-entropy-and-gini-index-for-a-partitioned-table/</link>
		<comments>http://vadimtropashko.wordpress.com/2012/01/26/caclulating-entropy-and-gini-index-for-a-partitioned-table/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 23:07:59 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=658</guid>
		<description><![CDATA[20th century has been highlighted by the two notable insights onto the nature of information. In 1948, Claude Shannon published classic paper &#8220;A Mathematical Theory of Communication&#8221; suggesting quantitative information measure &#8212; entropy &#8212; as average number of bits needed to store or communicate one symbol in a message. The paper has tremendous impact: it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=658&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>20th century has been highlighted by the two notable insights onto the nature of <em>information</em>. In 1948, Claude Shannon published classic paper &#8220;A Mathematical Theory of Communication&#8221; suggesting <em>quantitative</em> information measure &#8212; entropy &#8212; as average number of bits needed to store or communicate one symbol in a message. The paper has tremendous impact: it launched the whole new discipline &#8212; the <em>Information Theory</em>. Two decades later Edgar Codd invented the Relational Model, which equipped previously vague concept of &#8220;information pieces&#8221; with formal <em>structure</em>. </p>
<p>Since then there was at least one direct attempt to marry the two perspectives when Jürg Kohlas proposed <a href="http://en.wikipedia.org/wiki/Information_algebra">Information Algebra</a>. Other, less ambitious connections between the two disciplines were discovered within relational database dependency theory. Squeezed into one sentence this approach introduces <a href="http://www.cs.indiana.edu/l/www/pub/techreports/TR531.pdf">quantitative measure of attribute dependency</a> and proceeds expressing known dependencies (functional, multivalued, etc) in their terms. This blog posting pursues even more modest goal: first, describing a well known characterization of functional dependencies in terms of <a href="http://vadimtropashko.wordpress.com/relational-lattice/lattice-perspective-into-funcional-dependencies/">lattice partitions</a>, then calculating partition lattice entropy and Gini index and, finally, proving that all three orders are consistent.</p>
<p>Let&#8217;s start with relation example:</p>
<p><pre class="brush: java;">
Classes=[Prof    Course  Time]
         Libkin  DB101   Tue200
         Libkin  DB101   Thu500
         Gromov  Math    Tue200
         Gromov  Math    Thu500
         Vianu   DB101   Tue200
;
</pre>  </p>
<p>A binary partition of relation attributes, say <img src='http://s0.wp.com/latex.php?latex=%5C%7BProf%5C%7D%7C%5C%7BCourse%2CTime%5C%7D+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;{Prof&#92;}|&#92;{Course,Time&#92;} ' title='&#92;{Prof&#92;}|&#92;{Course,Time&#92;} ' class='latex' /> partitions the <code>Classes</code> tuples into 3 sets: </p>
<p><img src="http://vadimtropashko.files.wordpress.com/2012/01/table_partitions2.jpg?w=480" alt="" title="table_partitions" class="alignnone size-full wp-image-660" /></p>
<p><a href="http://vadimtropashko.wordpress.com/relational-programming-with-qbql/">QBQL Relational programming system</a> calculates partitions via binary operation; in our running example </p>
<p><pre class="brush: java;">
Classes#[Prof];
</pre></p>
<p>which outputs</p>
<p><pre class="brush: java;">
Classes#[Prof] = &lt;Libkin,DB101,Tue200&gt; &lt;Libkin,DB101,Thu500&gt; | 
                 &lt;Gromov,Math,Tue200&gt; &lt;Gromov,Math,Thu500&gt; | 
                 &lt;Vianu,DB101,Tue200&gt;;
</pre></p>
<p>Partitions can be compared pairwise: informally, partition <img src='http://s0.wp.com/latex.php?latex=x+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='x ' title='x ' class='latex' /> is <em>greater than</em> partition <img src='http://s0.wp.com/latex.php?latex=y+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='y ' title='y ' class='latex' /> if it is more coarse. Our next step is proving that this ordering is consistent with two numerical partition measures.</p>
<p><em>Partition entropy</em> is defined via Shannon information measure formula</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Csum%5Climits_%7Bi%3D0%7D%5En+p_i%5Cln%28p_i%29+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;displaystyle&#92;sum&#92;limits_{i=0}^n p_i&#92;ln(p_i) ' title='&#92;displaystyle&#92;sum&#92;limits_{i=0}^n p_i&#92;ln(p_i) ' class='latex' /> </p>
<p>where summation ranges over partitions and  <img src='http://s0.wp.com/latex.php?latex=p_i+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p_i ' title='p_i ' class='latex' /> is probability of selecting a tuple from partition <img src='http://s0.wp.com/latex.php?latex=i+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='i ' title='i ' class='latex' />. Let&#8217;s calculate entropy of the <code>Classes#[Prof]</code> partition in our example. Again, we automate this task with QBQL, and since later on we would like to calculate entropy of other partitions, we&#8217;ll provide generic definition. Let&#8217;s emphasize that this theoretically humble idea is one of the major practical benefits of QBQL over SQL and Datalog. First, we define 3 empty relations</p>
<p><pre class="brush: java;">
CntRelHdr = [cnt];
CardRelHdr = [card];
plpHdr = [plp];
</pre></p>
<p>This is just implementation artifact/bug as QBQL should be able to inline these relvars into any query. Then we progresively define partition probabilities <code>&lt;Prob&gt;</code> and entropy <code>&lt;Entropy&gt;</code> as binary operations:</p>
<p><pre class="brush: java;">
x &lt;Prob&gt; y = ((x |v| (y ^ CntRelHdr)) ^ (x |v| CardRelHdr)) /^ &quot;cnt / card = prob&quot;.
x &lt;Entropy&gt; y = ((((x &lt;Prob&gt; y) ^ &quot;ln(prob)=lp&quot;) /^ &quot;prob*lp=plp&quot;) v plpHdr) /= &quot;result += plp&quot;.
</pre></p>
<p>The definitions are generic, because you can plug in any two relations in place of <code>x</code> and <code>y</code>. For example, if you are interested in calculating the entropy of <code>Classes#[Prof]</code>, you just type:</p>
<p><pre class="brush: java;">
Classes &lt;Entropy&gt; [Prof];
</pre></p>
<p>Let&#8217;s walk trough <code>&lt;Prob&gt;</code> implementation. The expression <code>y ^ CntRelHdr</code> is a join of relation <code>y</code> with previously defined empty relation <code>CntRelHdr</code>, and since their attribute sets are disjoint it is a Cartesian product. In other words, we just want a set of attributes from relation <code>y</code> amended by one more attribute <code>cnt</code>. At the next step &#8212; <code>x |v| (y ^ CntRelHdr)</code> &#8212; we see something that appears as unfamiliar binary infix operator <code>|v|</code> applied to our previous result and relation <code>x</code>. The <code>v</code> symbols is reminiscent of inner union (which is generalization of union and projection) amended with the vertical bars, which in standard math notation usually denotes cardinality. It is SQL <code>group by</code> with <code>count</code>ing a counterpart in QBQL notation; the grouping is done over the set of common arguments of the two relations <code>x</code> and <code>y ^ CntRelHdr</code>, while the <code>count</code> function column header is set of attributes of <code>y ^ CntRelHdr</code> which is not in <code>x</code>. In a typical application, such as <code>Classes &lt;Entropy&gt; [Prof]</code>, the set of attributes of <code>x</code> is subset of that of <code>y</code>. Therefore, the name of the counting attribute is <code>cnt</code>. At the other branch, of the expression tree we compute <code>x |v| CardRelHdr</code>. Here relation attributes are disjoint, therefore this is just counting with no grouping (which is equivalent to counting with grouping over empty set). The two previous results <code>(x |v| (y ^ CntRelHdr)</code> and <code>x |v| CardRelHdr</code> again have disjoint set of attributes, so joining them is essentially a cartesian product. The final operation &#8212; relational composition with the <code>"cnt / card = prob"</code> (which is user-defined ternary predicate <code>Times</code> in disguise) &#8212; calculates probabilities for each table partition. Again, let&#8217;s not be distracted by the fact that this query is elementary in SQL: </p>
<p><pre class="brush: sql;">
select Prof, count(*)/card prob
from Classes, (select count(*) card from Classes)
group by Prof
</pre> </p>
<p>First, it is not generic (as it should be rewritten for every other target relation and different subsets of its attributes); second, it uses ad-hock tuple-level expression evaluation (division operator). In our example, after we have defined generic binary entropy operation, then calculating entropy values for all possible splits of relation attributes is as succinct as it can possibly be:</p>
<p><pre class="brush: java;">
Classes &lt;Entropy&gt; [Prof]; 
Classes &lt;Entropy&gt; [Course]; 
Classes &lt;Entropy&gt; [Time]; 
Classes &lt;Entropy&gt; [Prof Course]; 
Classes &lt;Entropy&gt; [Course Time]; 
Classes &lt;Entropy&gt; [Prof Time]; 
Classes &lt;Entropy&gt; [Prof Course Time];
</pre></p>
<p>The entropy values numerical order is consistent with partitioning order and this is not a coincidence. Consider a single partition <img src='http://s0.wp.com/latex.php?latex=%5C%7Ba_1%2Ca_2%2C...%2Ca_n%5C%7D+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;{a_1,a_2,...,a_n&#92;} ' title='&#92;{a_1,a_2,...,a_n&#92;} ' class='latex' /> split into the two <img src='http://s0.wp.com/latex.php?latex=%5C%7Ba_1%2Ca_2%2C...%2Ca_i%5C%7D+%7C+%5C%7Ba_i%2C...%2Ca_n%5C%7D+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;{a_1,a_2,...,a_i&#92;} | &#92;{a_i,...,a_n&#92;} ' title='&#92;{a_1,a_2,...,a_i&#92;} | &#92;{a_i,...,a_n&#92;} ' class='latex' /> and assume that both were the part of bigger partition of the set of <img src='http://s0.wp.com/latex.php?latex=N+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='N ' title='N ' class='latex' /> elements. Then, the entropy changes from</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7Bn%7D%7BN%7D+%5Cln%28%5Cfrac%7Bn%7D%7BN%7D%29+%2B+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;frac{n}{N} &#92;ln(&#92;frac{n}{N}) + ' title='&#92;frac{n}{N} &#92;ln(&#92;frac{n}{N}) + ' class='latex' /> <em>entropy of other pieces</em></p>
<p>to</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7Bi%7D%7BN%7D+%5Cln%28%5Cfrac%7Bi%7D%7BN%7D%29+%2B+%5Cfrac%7Bn-i%7D%7BN%7D+%5Cln%28%5Cfrac%7Bn-i%7D%7BN%7D%29+%2B+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;frac{i}{N} &#92;ln(&#92;frac{i}{N}) + &#92;frac{n-i}{N} &#92;ln(&#92;frac{n-i}{N}) + ' title='&#92;frac{i}{N} &#92;ln(&#92;frac{i}{N}) + &#92;frac{n-i}{N} &#92;ln(&#92;frac{n-i}{N}) + ' class='latex' /> <em>the same entropy of the rest of the pieces<br />
</em><br />
Since the first term of the former sum can be rewritten as</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7Bi%7D%7BN%7D+%5Cln%28%5Cfrac%7Bi%2Bn-i%7D%7BN%7D%29+%2B+%5Cfrac%7Bn-i%7D%7BN%7D+%5Cln%28%5Cfrac%7Bn-i%2Bi%7D%7BN%7D%29+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;frac{i}{N} &#92;ln(&#92;frac{i+n-i}{N}) + &#92;frac{n-i}{N} &#92;ln(&#92;frac{n-i+i}{N}) ' title='&#92;frac{i}{N} &#92;ln(&#92;frac{i+n-i}{N}) + &#92;frac{n-i}{N} &#92;ln(&#92;frac{n-i+i}{N}) ' class='latex' /></p>
<p>it is greater than the later. Therefore, we have established that entropy is monotonically increasing along with partition granularity. Shannon Entropy function is not unique in that respect. The similar proposition is valid for <em>Gini Index</em>:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Csum%5Climits_%7Bi%3D0%7D%5En+p_i%281-p_i%29+&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;displaystyle&#92;sum&#92;limits_{i=0}^n p_i(1-p_i) ' title='&#92;displaystyle&#92;sum&#92;limits_{i=0}^n p_i(1-p_i) ' class='latex' /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/658/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/658/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/658/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/658/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/658/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/658/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/658/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/658/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/658/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/658/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/658/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/658/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/658/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/658/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=658&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2012/01/26/caclulating-entropy-and-gini-index-for-a-partitioned-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>

		<media:content url="http://vadimtropashko.files.wordpress.com/2012/01/table_partitions2.jpg" medium="image">
			<media:title type="html">table_partitions</media:title>
		</media:content>
	</item>
		<item>
		<title>Documentation Code Snippets</title>
		<link>http://vadimtropashko.wordpress.com/2011/10/11/documentation-code-snippets/</link>
		<comments>http://vadimtropashko.wordpress.com/2011/10/11/documentation-code-snippets/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 20:14:21 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[SQL Developer]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=646</guid>
		<description><![CDATA[Code templates/snippets is one of modern IDE facilities accelerating programming. Some time ago I used to complain about cumbersome main() function signature in Java which escaped my limited memorization abilities until learning that there is convenient code template offered by code assist, so the syntax doesn&#8217;t matter. Sometimes the answer is just ctrl-space away! SQL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=646&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Code templates/snippets is one of modern IDE facilities accelerating programming. Some time ago I used to complain about cumbersome <code>main()</code> function signature in Java which escaped my limited memorization abilities until learning that there is convenient code template offered by code assist, so the syntax doesn&#8217;t matter. Sometimes the answer is just <em>ctrl-space</em> away!</p>
<p>SQL Developer 3.1 preview release is out and offers improvements in snippet/template arena. First, the old user-programmed templates and snippets are demoted from code assist/insight. You still can invoke them traditional way. The SQL&amp;PL/SQL fragments shown in code insight are fetched from documentation. That&#8217;s right, Oracle documentation contains hundreds if not thousands of code snippets, therefore why insist on entering them manually?</p>
<p>Let&#8217;s go through examples. Starting anonymous PL/SQL block prompts code insight like this: </p>
<p><a href="http://vadimtropashko.files.wordpress.com/2011/10/begin_ctrl_space.jpg"><img src="http://vadimtropashko.files.wordpress.com/2011/10/begin_ctrl_space.jpg?w=480&#038;h=240" alt="" title="begin_ctrl_space" width="480" height="240" class="alignnone size-full wp-image-648" /></a> </p>
<p>The first entry here is an individual keyword suggestion. The three next listings are code fragments captured from SQL history. Then there is <code>"..."</code> prompting that the list can be expanded, followed by the three entries from documentation. Selecting the first one outputs:</p>
<p><a href="http://vadimtropashko.files.wordpress.com/2011/10/begin_p_end.jpg"><img src="http://vadimtropashko.files.wordpress.com/2011/10/begin_p_end.jpg?w=480&#038;h=240" alt="" title="begin_p_end" width="480" height="240" class="alignnone size-full wp-image-649" /></a></p>
<p>Code insight is syntax driven; the code snippet is suggested only in the appropriate context. For example, a standalone <code>"exc"</code> prefix won&#8217;t bring any exception snippets, while within our anonymous PL/SQL block it would:</p>
<p><a href="http://vadimtropashko.files.wordpress.com/2011/10/exc_ctrl_space.jpg"><img src="http://vadimtropashko.files.wordpress.com/2011/10/exc_ctrl_space.jpg?w=480&#038;h=240" alt="" title="exc_ctrl_space" width="480" height="240" class="alignnone size-full wp-image-650" /></a> </p>
<p>If you are wondering where particular snippet is coming from, you can press the button with library icon. It will open new browser window pointing to the relevant documentation page:</p>
<p><a href="http://vadimtropashko.files.wordpress.com/2011/10/exc_doc.jpg"><img src="http://vadimtropashko.files.wordpress.com/2011/10/exc_doc.jpg?w=480&#038;h=480" alt="" title="exc_doc" width="480" height="480" class="alignnone size-full wp-image-651" /></a><br />
This feature may compete with Google for the fastest way to a forgotten corner of oracle documentation. Try it: <code>REGEXP</code> signature, recursive <code>WITH</code>, every other clause from humongous SQL syntax is right there at you keystroke.   </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/646/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/646/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/646/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=646&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2011/10/11/documentation-code-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>

		<media:content url="http://vadimtropashko.files.wordpress.com/2011/10/begin_ctrl_space.jpg" medium="image">
			<media:title type="html">begin_ctrl_space</media:title>
		</media:content>

		<media:content url="http://vadimtropashko.files.wordpress.com/2011/10/begin_p_end.jpg" medium="image">
			<media:title type="html">begin_p_end</media:title>
		</media:content>

		<media:content url="http://vadimtropashko.files.wordpress.com/2011/10/exc_ctrl_space.jpg" medium="image">
			<media:title type="html">exc_ctrl_space</media:title>
		</media:content>

		<media:content url="http://vadimtropashko.files.wordpress.com/2011/10/exc_doc.jpg" medium="image">
			<media:title type="html">exc_doc</media:title>
		</media:content>
	</item>
		<item>
		<title>Select from Insert</title>
		<link>http://vadimtropashko.wordpress.com/2011/09/22/select-from-insert/</link>
		<comments>http://vadimtropashko.wordpress.com/2011/09/22/select-from-insert/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 21:48:49 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=640</guid>
		<description><![CDATA[People imagination has no limits. Where does it lead SQL? Here is some bizarre syntax: Wow, a whole semicolon has been spared &#8212; at the expense of syntax confusing relation with operator! You would think DB2 designers would become laughing stock of SQL community? Wrong. Be prepared for some competition: Then, why not INSERT as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=640&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>People imagination has no limits. Where does it lead SQL? Here is <a href="http://systeminetwork.com/article/select-insert-new-sql-function-system-i-v6r1">some bizarre syntax</a>:</p>
<p><pre class="brush: sql;">SELECT column1
  FROM FINAL TABLE
  (INSERT INTO t1 VALUES(1,'John Smith') )</pre></p>
<p>Wow, a whole semicolon has been spared &#8212; at the expense of syntax confusing relation with operator!</p>
<p>You would think DB2 designers would become laughing stock of SQL community? Wrong. Be prepared for some competition:</p>
<p><pre class="brush: sql;">WITH sal1 AS
(
   SELECT * FROM NEW
   (
     INSERT INTO EMPLOYEES(EMPLOYEE_ID, SALARY) VALUES(207, 1000)
   )
)
, sal2 AS
(
   SELECT * FROM NEW
   (
     UPDATE EMPLOYEES SET SALARY = SALARY*1.1
   )
)
SELECT * FROM EMPLOYEES;
</pre></p>
<p>Then, why not <code>INSERT as SELECT FROM (INSERT as SELECT)</code>, and so on. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/640/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=640&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2011/09/22/select-from-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>
	</item>
		<item>
		<title>TABLE_DUM divided by Relation</title>
		<link>http://vadimtropashko.wordpress.com/2011/09/01/table_dum-divided-by-a-relation/</link>
		<comments>http://vadimtropashko.wordpress.com/2011/09/01/table_dum-divided-by-a-relation/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 01:02:58 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Relational Theory]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=625</guid>
		<description><![CDATA[Here is curious identity: TABLE_DUM divided by a relation evaluates to the relation&#8217;s complement. Formally in QBQL: TABLE_DUM /= x = &#60;NOT&#62; x. What division am I talking about? Googling &#8220;relational division&#8221; brings up a list of usual suspects &#8212; articles by Date, Celko, etc &#8212; with some confusion leading to &#8220;Todd&#8217;s division&#8221;, ternary (!) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=625&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is curious identity:</p>
<p><strong>TABLE_DUM divided by a relation evaluates to the relation&#8217;s complement.</strong></p>
<p>Formally in <a href="http://vadimtropashko.wordpress.com/relational-programming-with-qbql/">QBQL</a>:</p>
<p><code>TABLE_DUM /= x  =  &lt;NOT&gt; x.</code></p>
<p>What <em>division</em> am I talking about? Googling &#8220;relational division&#8221; brings up a list of usual suspects &#8212; articles by Date, Celko, etc &#8212; with some confusion leading to &#8220;Todd&#8217;s division&#8221;, ternary (!) division operation and so on. QBQL follows much cleaner definitions of <em>set equality join</em>, <em>set containment join</em> and alike readily found in <a href="http://www.tks.informatik.uni-frankfurt.de/teaching-hu/SS06/DBT/downloads/LeindersVanDenBussche_PODS05.pdf">academic literature</a>. In the above identity the &#8220;/=&#8221; is binary set equality join operation, informally known as relational division.</p>
<p>Dual identity is also interesting. First, the dual of <code>TABLE_DUM</code>, aka <code>R00</code> is the universal relation <code>R11</code>. The dual of unary complement operation is inversion. Duality among multiple division-like operations is not evident, but the reader might verify that <em>set intersection join</em> analogous to composition in the <a href="http://en.wikipedia.org/wiki/Relation_algebra">algebra of Binary Relations</a> fits the bill:</p>
<p><code>R11 /^ x  =  &lt;INV&gt; x.</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/625/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/625/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/625/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/625/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/625/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/625/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/625/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/625/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/625/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/625/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/625/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/625/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/625/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/625/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=625&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2011/09/01/table_dum-divided-by-a-relation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>
	</item>
		<item>
		<title>Empty String vs NULL</title>
		<link>http://vadimtropashko.wordpress.com/2011/07/29/empty-string-vs-null/</link>
		<comments>http://vadimtropashko.wordpress.com/2011/07/29/empty-string-vs-null/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 19:12:42 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=615</guid>
		<description><![CDATA[How weird is the language you are programming on? User survey on stackoverflow is the second most voted thread. Somewhere on page 2 we encounter the following SQL code snippet: create table wtf (key number primary key, animal varchar2(10)); insert into wtf values (1,'dog'); insert into wtf values (2,''); insert into wtf values (3,'cat'); select [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=615&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>How weird is the language you are programming on? <a href="http://stackoverflow.com/questions/1995113/strangest-language-feature">User survey on stackoverflow</a> is the second most voted thread. Somewhere on page 2 we encounter the following SQL code snippet:  </p>
<p><code>create table wtf (key number primary key, animal varchar2(10));<br />
insert into wtf values (1,'dog');<br />
insert into wtf values (2,'');<br />
insert into wtf values (3,'cat');<br />
select * from wtf where animal  'cat';<br />
</code><br />
I don&#8217;t agree with the sentiment of that post. How exactly returning an animal (or any other thing for that matter) named with empty string of characters would make user happy? For all practical purposes empty string of data is useless and equating it with NULL just reduces complexity.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/615/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/615/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/615/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/615/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/615/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/615/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/615/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/615/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/615/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/615/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/615/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/615/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/615/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/615/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=615&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2011/07/29/empty-string-vs-null/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>
	</item>
		<item>
		<title>Search code in SQL Developer 3.0</title>
		<link>http://vadimtropashko.wordpress.com/2011/06/22/search-code-in-sql-developer-3-0/</link>
		<comments>http://vadimtropashko.wordpress.com/2011/06/22/search-code-in-sql-developer-3-0/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 18:51:29 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=607</guid>
		<description><![CDATA[Oracle 11g introduced &#8220;syntax aware&#8221; code search facility &#8212; PL/Scope. One can look up identifier definitions, usages, exceptions, which is much more sophisticated and targeted search compared to the old way of finding all of the occurrences of a string in the ALL_SOURCE. Certainly few developers are expected to use PL/Scope À la carte. IDEs, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=607&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Oracle 11g introduced &#8220;syntax aware&#8221; code search facility &#8212; <a href="http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28424/adfns_plscope.htm">PL/Scope</a>. One can look up  identifier definitions, usages, exceptions, which is much more sophisticated and targeted search compared to the old way of finding all of the occurrences of a string in the <code>ALL_SOURCE</code>. Certainly few developers are expected to use PL/Scope À la carte. IDEs, such as SQL Developer, accommodated it within its [object] search. Here is a screen shot illustrating a search of formal parameter <code>P3</code>:</p>
<p><img src="http://vadimtropashko.files.wordpress.com/2011/06/find_db_obj_1.jpg?w=480" alt="" class="alignnone size-full wp-image-62" /></p>
<p>So, with PL/Scope available is the old way, that is finding all of the occurrences of a string in the <code>ALL_SOURCE</code>, obsolete? Yes, it has been effectively deprecated, which turned out to be ill-considered decision. Apparently, some people like the old way better, especially that there is no way to search the comments. The fix is expected in next SQL Developer release, but for now here is a workaround. Among the other things it demonstrates that many features are nearly duplicated, and certainly a search can be accommodated by <em>SQL Developer reports</em>. In fact, there is a off-the-shelf report &#8220;Search Source Code&#8221; already, although many would find the <code>owner = USER </code>predicate impeding their goal. With little effort, however, one can customize it to approximate to what the Search Panel does (for RDBMS versions below 11.1). One can even prettify the output with html formatting; here are the steps:</p>
<p>1. Go to reports tab -&gt; User Defined Reports and select &#8220;Add Report&#8221; from context menu<br />
2. Name the report, e.g. &#8220;Fancy all_source&#8221;, and copy and paste the following prettified query<br />
<pre class="brush: sql;">
select
    owner &quot;Owner&quot;,
    name  &quot;PL/SQL Object Name&quot;,
    type  &quot;Type&quot;,
    line  &quot;Line&quot;,
    '&lt;html&gt;&lt;font bgcolor=#dddddd&gt;'
    ||substr(text,1,instr(upper(text),upper(:TEXT_STRING))-1)||'&lt;/font&gt;'
    ||'&lt;font bgcolor=#bbffbb&gt;'
    ||substr(text,instr(upper(text),upper(:TEXT_STRING)),length(:TEXT_STRING))
    ||'&lt;/font&gt;'
    ||'&lt;html&gt;&lt;font bgcolor=#dddddd&gt;'
    ||substr(text,instr(upper(text),upper(:TEXT_STRING))+length(:TEXT_STRING))
          &quot;Text&quot;,
    owner  sdev_link_owner,
    name   sdev_link_name,
    type   sdev_link_type,
    line   sdev_link_line 
from sys.all_source
where (:TEXT_STRING is null or
           instr(upper(text),upper(:TEXT_STRING)) &gt; 0)
    and length(text)&lt;3000  --not like '%wrapped%'
    and name not like 'BIN$%'
    order by owner, name, type, line
</pre><br />
3. Use Go To option from context menu on PL/SQL object name to navigate to the PL/SQL compilation unit.</p>
<p>Here is a screen shot of the report output:<br />
<img src="http://vadimtropashko.files.wordpress.com/2011/06/find_db_obj_2.jpg?w=480" alt="" class="alignnone size-full wp-image-62" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/607/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=607&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2011/06/22/search-code-in-sql-developer-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>

		<media:content url="http://vadimtropashko.files.wordpress.com/2011/06/find_db_obj_1.jpg" medium="image" />

		<media:content url="http://vadimtropashko.files.wordpress.com/2011/06/find_db_obj_2.jpg" medium="image" />
	</item>
		<item>
		<title>ANSI join syntax</title>
		<link>http://vadimtropashko.wordpress.com/2011/03/02/ansi-join-syntax/</link>
		<comments>http://vadimtropashko.wordpress.com/2011/03/02/ansi-join-syntax/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 18:36:28 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=579</guid>
		<description><![CDATA[Here is unconventional way to write a query in ANSI SQL join syntax It is valid syntax according to ANSI 92. Indeed, the fragment is a qualified join which is a joined table which is a table reference. Therefore, one can just take conventional restrict-project-cartesian product query, and replace all the commas in the FROM [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=579&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is unconventional way to write a query in ANSI SQL join syntax </p>
<p><pre class="brush: sql;">SELECT 1
   FROM DEPARTMENTS C
        JOIN EMPLOYEES A
             JOIN JOBS B
     ON C.DEPARTMENT_ID = A.DEPARTMENT_ID
     ON A.JOB_ID = B.JOB_ID
</pre></p>
<p>It is valid syntax according to <a href="http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt">ANSI 92</a>. Indeed, the fragment </p>
<p><pre class="brush: sql;">EMPLOYEES A
             JOIN JOBS B
     ON C.DEPARTMENT_ID = A.DEPARTMENT_ID
</pre></p>
<p>is a <code>qualified join</code> which is a <code>joined table</code> which is a <code>table reference</code>. </p>
<p>Therefore, one can just take conventional <em>restrict-project-cartesian product</em> query, and replace all the commas in the <code>FROM</code> clause with the <code>JOIN</code> keyword, then replace <code>WHERE</code> and <code>AND</code> keywords with the <code>ON</code>. </p>
<p>An argument in favor of ANSI style is allegedly cleaner textbook example</p>
<p><pre class="brush: sql;">SELECT 1
   FROM DEPARTMENTS C
        JOIN EMPLOYEES A  ON C.DEPARTMENT_ID = A.DEPARTMENT_ID
        JOIN JOBS B  ON A.JOB_ID = B.JOB_ID
</pre></p>
<p>although, as we have witnessed, ANSI grammar doesn&#8217;t enforce it. A developer is free to mix the first and the second variant in unbelievably messy query!</p>
<p>My feelings is reflected in a quote by Anthony Molinaro (author of <a href="http://www.amazon.com/Cookbook-Cookbooks-OReilly-Anthony-Molinaro/dp/0596009763">&#8220;SQL Cookbook&#8221;</a>): </p>
<p><em>“Old style is short and sweet and perfect. ANSI dumbed it down, and for people who&#8217;ve been developing for sometime, it&#8217;s wholly unnecessary&#8221;.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/579/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=579&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2011/03/02/ansi-join-syntax/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL challenge #2</title>
		<link>http://vadimtropashko.wordpress.com/2011/02/14/sql-challenge-2/</link>
		<comments>http://vadimtropashko.wordpress.com/2011/02/14/sql-challenge-2/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 21:21:07 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=572</guid>
		<description><![CDATA[Here is a solution to Iggy Fernandez The Second SQL challenge: WITH T(W2,OUT) AS ( SELECT WORD2, WORD1 &#124;&#124; ' ' &#124;&#124; WORD2 &#124;&#124; ' ' &#124;&#124; WORD3 FROM RIDDLE UNION ALL SELECT R.WORD2, T1.out &#124;&#124; ' ' &#124;&#124; R.WORD2 &#124;&#124; ' ' &#124;&#124; T2.out FROM T T1, RIDDLE R, T T2 WHERE T1.W2 = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=572&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a solution to <em>Iggy Fernandez</em> <a href="http://www.nocoug.org/Journal/NoCOUG_Journal_201102.pdf">The Second SQL challenge</a>: </p>
<p><code>WITH T(W2,OUT) AS (<br />
  SELECT WORD2, WORD1 || ' ' || WORD2 || ' ' || WORD3 FROM RIDDLE<br />
UNION ALL<br />
  SELECT<br />
        R.WORD2,<br />
        T1.out || ' ' || R.WORD2 || ' ' || T2.out<br />
  FROM T T1, RIDDLE R, T T2<br />
  WHERE T1.W2 = R.WORD1 AND T2.W2 = R.WORD3<br />
) select out from t</code></p>
<p>(Be sure to have table columns of sufficient width). It outputs something like:</p>
<p> TRYING  TO  TYPE  ONE  HUNDRED  DISTINCT  WORDS  IN  A  SINGLE  PARAGRAPH  IS  REALLY  TOUGH  IF  I  CANNOT  REPEAT  ANY  OF  THEM  THEN  PROBABLY  THOSE  WITH  MANY  LETTERS  SHOULD  BE  USED  MAYBE  SOME  READERS  WILL  UTILIZE  DICTIONARIES  THESAURUSES  THESAURI  OR  POSSIBLY  EVEN  ENCYCLOPEDIAS  BUT  MY  PREFERENCE  HAS  ALWAYS  BEEN  THAT  GRAY  MATTER  BETWEEN  YOUR  EARS  SERIOUSLY  MARILYN  CHALLENGES  SUCH  AS  THIS  REQUIRE  SKILLS  BEYOND </p>
<p>P.S. It looks like I didn&#8217;t figure out tree structure correctly as the rhs of the tree is almost gibberish:</p>
<p>SCIENCE  AND  PHYSICS  SO  WHAT  DO  YOU  ASK  READING  COMPREHENSION  WRITING  ABILITY  GOOD  OLD  FASHIONED  ELBOW  GREASE  SCIENTISTS  DONT  CARE  ABOUT  STRUCTURE  THEY  WANT  RESULTS  HEY  LOOK  ONLY  ELEVEN  MORE  LEFT </p>
<p>Why the forementioned query didn&#8217;t connect it to the first part is another mystery&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/572/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/572/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/572/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/572/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/572/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/572/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/572/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/572/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/572/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/572/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/572/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/572/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/572/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/572/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=572&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2011/02/14/sql-challenge-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>
	</item>
		<item>
		<title>Making fun of Java in cubicle</title>
		<link>http://vadimtropashko.wordpress.com/2010/11/20/making-fun-of-java-in-cubicle/</link>
		<comments>http://vadimtropashko.wordpress.com/2010/11/20/making-fun-of-java-in-cubicle/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 19:39:41 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=557</guid>
		<description><![CDATA[This is a legitimate program in QBQL: which returns "for( int i = 0; i&#60;10; i++ )&#34;/=&#34;sum += i&#34;=[sum] 45 ; Here is detailed article.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=557&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a legitimate program in <a href="http://vadimtropashko.wordpress.com/relational-programming-with-qbql/">QBQL</a>:</p>
<p><pre class="brush: java;">
&quot;for( int i = 0; i&lt;10; i++ )&quot; /= 
    &quot;sum += i&quot;;</pre></p>
<p>which returns</p>
<p><code>"for( int i = 0; i&lt;10; i++ )&quot;/=&quot;sum += i&quot;=[sum]<br />
                                           45<br />
;<br />
</code><br />
Here is detailed <a href="http://vadimtropashko.wordpress.com/relational-programming-with-qbql/whats-in-a-name/">article</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/557/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=557&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2010/11/20/making-fun-of-java-in-cubicle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>
	</item>
		<item>
		<title>Pivot and Unpivot</title>
		<link>http://vadimtropashko.wordpress.com/2010/10/14/pivot-and-unpivot/</link>
		<comments>http://vadimtropashko.wordpress.com/2010/10/14/pivot-and-unpivot/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 02:51:37 +0000</pubDate>
		<dc:creator>Vadim Tropashko</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vadimtropashko.wordpress.com/?p=530</guid>
		<description><![CDATA[SQL has many flaws, and the fact that its syntax poorly reflects duality of pivot and unpivot queries is probably somewhere at the bottom of the list. To be fair, relational algebra doesn&#8217;t do any better. What are pivot and unpivot queries in QBQL? Consider the following matrix example: This 2&#215;2 matrix can be represented [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=530&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>SQL has many flaws, and the fact that its syntax poorly reflects duality of pivot and unpivot queries is probably somewhere at the bottom of the list. To be fair, relational algebra doesn&#8217;t do any better. What are pivot and unpivot queries in QBQL? </p>
<p>Consider the following matrix example:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cbegin%7Bbmatrix%7D+3+%26+1+%5C%5C1+%26+0+%5Cend%7Bbmatrix%7D&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='&#92;begin{bmatrix} 3 &amp; 1 &#92;&#92;1 &amp; 0 &#92;end{bmatrix}' title='&#92;begin{bmatrix} 3 &amp; 1 &#92;&#92;1 &amp; 0 &#92;end{bmatrix}' class='latex' /></p>
<p>This 2&#215;2 matrix can be represented relationally in two ways:<br />
• as ternary relation with two subscripts and one entry attribute:</p>
<p><pre class="brush: java;">
Au=[i j s]
    1 1 3
    1 2 1
    2 1 1
    2 2 0
;
</pre></p>
<p>• as rectangular array with dimension j pivoted into the columns j1 and j2:</p>
<p><pre class="brush: java;">Ap=[i j1 j2]
    1 3  1
    2 1  0
;
</pre></p>
<p>The expressing <code>Ap</code> in terms of <code>Au</code> is pivot operation, while representing <code>Au</code> in terms of <code>Ap</code> is unpivot. </p>
<p><pre class="brush: java;">
Au =
((Ap /^ [j1=s]) /^ [j]1)
v
((Ap /^ [j2=s]) /^ [j]2)
. 

Ap =
((Au /^ [j1=s]) /^ [j]1)
^
((Au /^ [j2=s]) /^ [j]2)
.
</pre></p>
<p>Notice that both expressinos are almost identical, so the duality of pivot and unpivot is exposed as formal relational lattice duality of join and union. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vadimtropashko.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vadimtropashko.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vadimtropashko.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vadimtropashko.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vadimtropashko.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vadimtropashko.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vadimtropashko.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vadimtropashko.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vadimtropashko.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vadimtropashko.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vadimtropashko.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vadimtropashko.wordpress.com/530/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vadimtropashko.wordpress.com/530/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vadimtropashko.wordpress.com/530/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vadimtropashko.wordpress.com&amp;blog=760039&amp;post=530&amp;subd=vadimtropashko&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vadimtropashko.wordpress.com/2010/10/14/pivot-and-unpivot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ded83ebd6144cad882e4912aa7d9202?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vadimtropashko</media:title>
		</media:content>
	</item>
	</channel>
</rss>
