<?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>Geoffrey FairchildGeoffrey Fairchild</title>
	<atom:link href="http://www.gfairchild.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gfairchild.com</link>
	<description>[insert witty tagline here]</description>
	<lastBuildDate>Thu, 02 May 2013 22:39:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>pyHarmonySearch supports Python&#8217;s multiprocessing module</title>
		<link>http://www.gfairchild.com/2013/05/02/pyharmonysearch-supports-pythons-multiprocessing-module/</link>
		<comments>http://www.gfairchild.com/2013/05/02/pyharmonysearch-supports-pythons-multiprocessing-module/#comments</comments>
		<pubDate>Thu, 02 May 2013 22:30:41 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=575</guid>
		<description><![CDATA[Yesterday, I added support for Python&#8217;s multiprocessing module to pyHarmonySearch. I use multiprocessing to run multiple harmony searches simultaneously. Since harmony search is stochastic, different results may be returned on each run. Some runs will be luckier than others, so I figured it makes sense to take advantage of multiple cores by running multiple search [...]]]></description>
				<content:encoded><![CDATA[<p>Yesterday, I added support for <a href="http://docs.python.org/2/library/multiprocessing.html" title="Python's multiprocessing module">Python&#8217;s multiprocessing module</a> to <a href="https://github.com/gfairchild/pyHarmonySearch" title="pyHarmonySearch">pyHarmonySearch</a>. I use <code>multiprocessing</code> to run multiple harmony searches simultaneously. Since harmony search is stochastic, different results may be returned on each run. Some runs will be luckier than others, so I figured it makes sense to take advantage of multiple cores by running multiple search iterations. The resulting solution is the best one found across all iterations.</p>
<p>I don&#8217;t have a rigorous proof demonstrating this, but I&#8217;ve seen better results in the test objective functions I&#8217;ve included on GitHub. On machines with many cores, better results could come at a minimal extra wall time cost. Furthermore, instead of running a single HS instance with a very large number of improvisations, it <em>may</em> be beneficial to simultaneously run multiple HS instances, each with a smaller number of improvisations. This is all conjecture, though, and it likely depends on the objective function being studied.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2013/05/02/pyharmonysearch-supports-pythons-multiprocessing-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pyHarmonySearch now supports discrete variables</title>
		<link>http://www.gfairchild.com/2013/04/22/pyharmonysearch-now-supports-discrete-variables/</link>
		<comments>http://www.gfairchild.com/2013/04/22/pyharmonysearch-now-supports-discrete-variables/#comments</comments>
		<pubDate>Mon, 22 Apr 2013 15:36:14 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=569</guid>
		<description><![CDATA[Last week, I introduced pyHarmonySearch, a Python implementation of the harmony search meta-heuristic search algorithm. The original implementation only supported continuous variables. However, I recently added support for discrete variables. I provide examples in the code of both cases. If you find pyHarmonySearch useful, please let me know!]]></description>
				<content:encoded><![CDATA[<p>Last week, I introduced <a href="https://github.com/gfairchild/pyHarmonySearch" title="pyHarmonySearch">pyHarmonySearch</a>, a Python implementation of the harmony search meta-heuristic search algorithm. The original implementation only supported continuous variables. However, I recently added support for discrete variables. I provide examples in the code of both cases.</p>
<p>If you find pyHarmonySearch useful, please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2013/04/22/pyharmonysearch-now-supports-discrete-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing pyHarmonySearch!</title>
		<link>http://www.gfairchild.com/2013/04/17/introducing-pyharmonysearch/</link>
		<comments>http://www.gfairchild.com/2013/04/17/introducing-pyharmonysearch/#comments</comments>
		<pubDate>Wed, 17 Apr 2013 22:38:17 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=562</guid>
		<description><![CDATA[For a paper I&#8217;ve been working on, I implemented the harmony search (HS) global optimization algorithm in Python. HS is a cool evolutionary-like optimization algorithm that mimics jazz improvisation. Wiki says: In the HS algorithm, each musician (= decision variable) plays (= generates) a note (= a value) for finding a best harmony (= global [...]]]></description>
				<content:encoded><![CDATA[<p>For a paper I&#8217;ve been working on, I implemented the <a href="http://en.wikipedia.org/wiki/Harmony_search" title="harmony search (HS) global optimization algorithm">harmony search (HS) global optimization algorithm</a> in Python. HS is a cool evolutionary-like optimization algorithm that mimics jazz improvisation. Wiki says:</p>
<blockquote><p>In the HS algorithm, each musician (= decision variable) plays (= generates) a note (= a value) for finding a best harmony (= global optimum) all together.</p></blockquote>
<p>I&#8217;m currently a graduate research assistant at <a href="http://www.lanl.gov/" title="Los Alamos National Laboratory">Los Alamos National Laboratory</a>. While I&#8217;ve actually had the code finished for several months, I had to wait for approval before I could give it out. It got approved today, so it&#8217;s now officially live on <a href="https://github.com/gfairchild/pyHarmonySearch" title="GitHub">GitHub</a>.</p>
<p>Right now, my HS implementation only handles the continuous case. I&#8217;d like to add support for discrete variables, but it&#8217;s not clear how to handle pitch adjustment&#8230;.</p>
<p>If you find this useful, drop me a note!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2013/04/17/introducing-pyharmonysearch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ZIP codes shouldn&#8217;t be represented as integers!</title>
		<link>http://www.gfairchild.com/2012/11/26/zip-codes-shouldnt-be-represented-as-integers/</link>
		<comments>http://www.gfairchild.com/2012/11/26/zip-codes-shouldnt-be-represented-as-integers/#comments</comments>
		<pubDate>Mon, 26 Nov 2012 21:19:40 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=513</guid>
		<description><![CDATA[This is just a quick post to point out that ZIP codes should never be stored or represented as integers. ZIP codes should always be stored and represented as strings. Take the ZIP code 07755 (Oakhurst, NJ), for example. Any reasonable parsing algorithm will correct read in 07755, but 07755 will be immediately converted to [...]]]></description>
				<content:encoded><![CDATA[<p>This is just a quick post to point out that ZIP codes should <em>never</em> be stored or represented as integers. ZIP codes should <em>always</em> be stored and represented as strings. Take the ZIP code 07755 (Oakhurst, NJ), for example. Any reasonable parsing algorithm will correct read in 07755, but 07755 will be immediately converted to 7755 as leading zeros mean nothing in the context of integers. The problem doesn&#8217;t become apparent until it becomes time to output the ZIP code (for example, in a KML file). 7755 is not a valid ZIP code.</p>
<p>A common place where this problem pops up is in web apps where user ZIP codes are stored. In Django, for example, you may be tempted to add the following field to a model:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #008000;">zip</span> <span style="color: #66cc66;">=</span> models.<span style="color: black;">IntegerField</span><span style="color: black;">&#40;</span>max_length<span style="color: #66cc66;">=</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>While this will certainly work, if you ever need to display user ZIP codes (e.g., to let a user view their current address), leading zeros won&#8217;t be displayed. Instead, the correct way to represent a ZIP code would be:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #008000;">zip</span> <span style="color: #66cc66;">=</span> models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length<span style="color: #66cc66;">=</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Now, leading zeros won&#8217;t get cut off.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2012/11/26/zip-codes-shouldnt-be-represented-as-integers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Rename Columns in an SQLite Database</title>
		<link>http://www.gfairchild.com/2012/08/03/how-to-rename-columns-in-an-sqlite-database/</link>
		<comments>http://www.gfairchild.com/2012/08/03/how-to-rename-columns-in-an-sqlite-database/#comments</comments>
		<pubDate>Fri, 03 Aug 2012 21:18:04 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=429</guid>
		<description><![CDATA[I just solved a problem where I needed to rename some columns in an SQLite3 database. Unfortunately, SQLite3&#8242;s ALTER TABLE command doesn&#8217;t have the ability to rename columns in tables. Most Google results offered solutions such as creating a new table, copying the data over, and then dropping the old table. While this is fine [...]]]></description>
				<content:encoded><![CDATA[<p>I just solved a problem where I needed to rename some columns in an SQLite3 database. Unfortunately, SQLite3&#8242;s <a title="ALTER TABLE" href="http://www.sqlite.org/lang_altertable.html">ALTER TABLE</a> command doesn&#8217;t have the ability to rename columns in tables. Most Google results offered solutions such as creating a new table, copying the data over, and then dropping the old table. While this is fine for probably 99% of SQLite3 databases, the table I&#8217;m dealing with has almost 3 billion rows (yes, I have an SQLite3 database with 3&#215;10<sup>9</sup> rows). Recreating the table (specifically, the indices on the columns) would take too long. It took me about 24 hours to create the indices on a supercomputer with 512gb of RAM, and I didn&#8217;t want to go through that again.</p>
<p>I stumbled on two <a title="separate" href="http://stackoverflow.com/questions/805363/how-do-i-rename-a-column-in-a-sqlite-database-table">separate</a> <a title="posts" href="http://www.mailinglistarchive.com/html/sqlite-users@sqlite.org/2011-05/msg00385.html">posts</a> that seemed to offer solutions, and I got it working using them. I just wanted to write up this blog entry to clarify a few things and to show this in action.</p>
<p><span style="color: #ff0000;"><strong>Backup your database!</strong></span> Seriously, back it up. The first time I tried this, I corrupted mine because I forgot to update the corresponding index. Were it not for the backup, I&#8217;d be spending another several days recreating it from scratch.</p>
<p>I&#8217;m on a *nix box, so I&#8217;m interacting with the database using <code>sqlite3</code> from the command line. I think this is simplest and safest because you can double-check your progress as you go before you commit the changes to the database. As an example, I&#8217;ll show you the table I was working with:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> people <span style="color: #66cc66;">&#40;</span>
	id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span>
	state_id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	county <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	age <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	gender TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> <span style="color: #808080; font-style: italic;">-- M or F</span>
	income <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">INDEX</span> people_county_index <span style="color: #993333; font-weight: bold;">ON</span> people<span style="color: #66cc66;">&#40;</span>county<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>What I realized is that I incorrectly named the <code>county</code> column. It should&#8217;ve been <code>county_id</code>. In order to change the name of the column, I must change the index as well. Here is how it&#8217;s done:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">BEGIN</span>; <span style="color: #808080; font-style: italic;">--start a transaction; this ensures that your changes won't be written until you COMMIT</span>
<span style="color: #66cc66;">.</span>schema <span style="color: #808080; font-style: italic;">--this will show you your current schema</span>
PRAGMA writable_schema<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>; <span style="color: #808080; font-style: italic;">--this enables you to edit the schema</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> sqlite_master; <span style="color: #808080; font-style: italic;">--show the raw data SQLite saves related to your schema</span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> sqlite_master <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">=</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'county'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'county_id'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'people'</span>; <span style="color: #808080; font-style: italic;">--simple string replace</span>
<span style="color: #66cc66;">.</span>schema <span style="color: #808080; font-style: italic;">--verify CREATE TABLE is correct</span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> sqlite_master <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'CREATE INDEX people_county_id_index on people(county_id)'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'people_county_index'</span>; <span style="color: #808080; font-style: italic;">--update index SQL</span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> sqlite_master <span style="color: #993333; font-weight: bold;">SET</span> name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'people_county_id_index'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'people_county_index'</span>; <span style="color: #808080; font-style: italic;">--update index name</span>
<span style="color: #66cc66;">.</span>schema <span style="color: #808080; font-style: italic;">--verify index is correct</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> sqlite_master; <span style="color: #808080; font-style: italic;">--double-check all raw data once more</span>
PRAGMA writable_schema<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>; <span style="color: #808080; font-style: italic;">--disable editing the schema</span>
COMMIT; <span style="color: #808080; font-style: italic;">--save the changes to the database</span>
<span style="color: #66cc66;">.</span>exit</pre></td></tr></table></div>

<p>After you verify that things look right, run <a href="http://www.sqlite.org/lang_analyze.html" title="ANALYZE">ANALYZE</a> to update the query planner&#8217;s statistics. This hack seemed to mess up the query planner for my database, but <code>ANALYZE</code> fixed it. If you&#8217;re still paranoid, run <a href="http://www.sqlite.org/pragma.html#pragma_integrity_check" title="PRAGMA integrity_check;">PRAGMA integrity_check;</a> after <code>ANALYZE</code>.</p>
<p>That&#8217;s all there is to it. <code>sqlite_master</code> is just a regular SQL table, so you can modify it like any other. Note that the call to <code>replace(x, y, z)</code> will replace all occurrences of <code>y</code> with <code>z</code> in the string <code>x</code>. This means that if &#8220;county&#8221; existed anywhere else in the <code>CREATE TABLE people</code> statement, it would be replaced. As a result, be careful when using <code>replace()</code>.</p>
<p>Also, if anyone has any questions regarding big/huge/gigantic SQLite3 databases, feel free to ask. Mine is 280gb and contains about 3.5 billion records split between 4 tables. Performance is quite good, but it took quite a bit of work to get there, and there were a lot of hard lessons learned along the way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2012/08/03/how-to-rename-columns-in-an-sqlite-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Query for Finding ZCTAs Present in Multiple States</title>
		<link>http://www.gfairchild.com/2011/12/23/sql-query-for-finding-zctas-present-in-multiple-states/</link>
		<comments>http://www.gfairchild.com/2011/12/23/sql-query-for-finding-zctas-present-in-multiple-states/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 02:18:29 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=388</guid>
		<description><![CDATA[Using the previously described 2010 US Census SQLite database I created, there are a whole slew of neat things that can be learned fairly easily. For example, I was curious which ZCTAs are contained in more than one state. Hammerite from Something Awful created a really nice SQL query for solving this problem in this [...]]]></description>
				<content:encoded><![CDATA[<p>Using the previously described <a href="http://www.gfairchild.com/2011/12/20/update-to-2010-census-sqlite-population-database/" title="2010 US Census SQLite database">2010 US Census SQLite database</a> I created, there are a whole slew of neat things that can be learned fairly easily. For example, I was curious which ZCTAs are contained in more than one state. Hammerite from Something Awful created a really nice SQL query for solving this problem in <a href="http://forums.somethingawful.com/showthread.php?threadid=2672629&#038;pagenumber=131#post398899029" title="this post">this post</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">DISTINCT</span>
	zctas<span style="color: #66cc66;">.</span>zcta<span style="color: #66cc66;">,</span> states<span style="color: #66cc66;">.</span>state
<span style="color: #993333; font-weight: bold;">FROM</span>
	states_zctas
	<span style="color: #993333; font-weight: bold;">JOIN</span> states_zctas <span style="color: #993333; font-weight: bold;">AS</span> states_zctas_different <span style="color: #993333; font-weight: bold;">ON</span>
		states_zctas<span style="color: #66cc66;">.</span>zcta_id <span style="color: #66cc66;">=</span> states_zctas_different<span style="color: #66cc66;">.</span>zcta_id <span style="color: #993333; font-weight: bold;">AND</span>
		states_zctas<span style="color: #66cc66;">.</span>state_id <span style="color: #66cc66;">&lt;&gt;</span> states_zctas_different<span style="color: #66cc66;">.</span>state_id
	<span style="color: #993333; font-weight: bold;">JOIN</span> zctas <span style="color: #993333; font-weight: bold;">ON</span> states_zctas<span style="color: #66cc66;">.</span>zcta_id <span style="color: #66cc66;">=</span> zctas<span style="color: #66cc66;">.</span>id
	<span style="color: #993333; font-weight: bold;">JOIN</span> states <span style="color: #993333; font-weight: bold;">ON</span> states_zctas<span style="color: #66cc66;">.</span>state_id <span style="color: #66cc66;">=</span> states<span style="color: #66cc66;">.</span>id
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> zctas<span style="color: #66cc66;">.</span>zcta <span style="color: #993333; font-weight: bold;">ASC</span>;</pre></td></tr></table></div>

<p>The results look like this:</p>
<table>
<tr>
<th style="text-align: center; padding: 0px;"><strong>zcta</strong></th>
<th style="text-align: center; padding: 0px;"><strong>state</strong></th>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">02861</td>
<td style="text-align: center; padding: 0px;">Rhode Island</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">02861</td>
<td style="text-align: center; padding: 0px;">Massachusetts</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">03579</td>
<td style="text-align: center; padding: 0px;">New Hampshire</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">03579</td>
<td style="text-align: center; padding: 0px;">Maine</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">20135</td>
<td style="text-align: center; padding: 0px;">West Virginia</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">20135</td>
<td style="text-align: center; padding: 0px;">Virginia</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">21912</td>
<td style="text-align: center; padding: 0px;">Maryland</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">21912</td>
<td style="text-align: center; padding: 0px;">Delaware</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">24604</td>
<td style="text-align: center; padding: 0px;">West Virginia</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">24604</td>
<td style="text-align: center; padding: 0px;">Virginia</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">30165</td>
<td style="text-align: center; padding: 0px;">Georgia</td>
</tr>
<tr>
<td style="text-align: center; padding: 0px;">30165</td>
<td style="text-align: center; padding: 0px;">Alabama</td>
</tr>
</table>
<p>So, as it turns out, there are 103 ZCTAs that are present in more than 1 state. Unsurprisingly, there&#8217;s no ZCTA present in more than two states.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2011/12/23/sql-query-for-finding-zctas-present-in-multiple-states/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update to 2010 Census SQLite Population Database</title>
		<link>http://www.gfairchild.com/2011/12/20/update-to-2010-census-sqlite-population-database/</link>
		<comments>http://www.gfairchild.com/2011/12/20/update-to-2010-census-sqlite-population-database/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 21:38:28 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=371</guid>
		<description><![CDATA[About a week ago, I posted an SQLite database containing 2010 US Census population data. However, I discovered a slight problem recently and am releasing an update today. The problem is that I made the assumption that there is a one-to-many relationship between states and ZCTAs. In other words, I made the assumption that states [...]]]></description>
				<content:encoded><![CDATA[<p>About a week ago, I posted an <a title="SQLite database containing 2010 US Census population data" href="http://www.gfairchild.com/2011/12/13/2010-census-sqlite-database/">SQLite database containing 2010 US Census population data</a>. However, I discovered a slight problem recently and am releasing an update today. The problem is that I made the assumption that there is a one-to-many relationship between states and ZCTAs. In other words, I made the assumption that states contain many ZCTAs. While this relationship certainly exists, it&#8217;s actually too simple. The real relationship is many-to-many. There are a few instances of ZCTAs that are actually contained in multiple states (the ZCTA 30165, for example, is located in both Georgia and Alabama).</p>
<p>This updated schema accounts for this many-to-many relationship:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> states <span style="color: #66cc66;">&#40;</span>
	id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	state TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_longitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_latitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_lt5 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_5to9 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_10to14 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_15to17 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_18to19 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_20 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_21 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_22to24 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_25to29 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_30to34 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_35to39 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_40to44 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_45to49 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_50to54 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_55to59 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_60to61 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_62to64 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_65to66 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_67to69 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_70to74 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_75to79 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_80to84 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_ge85 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_lt5 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_5to9 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_10to14 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_15to17 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_18to19 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_20 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_21 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_22to24 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_25to29 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_30to34 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_35to39 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_40to44 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_45to49 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_50to54 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_55to59 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_60to61 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_62to64 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_65to66 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_67to69 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_70to74 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_75to79 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_80to84 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_ge85 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> counties <span style="color: #66cc66;">&#40;</span>
	id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	state_id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	county TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_longitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_latitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_lt5 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_5to9 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_10to14 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_15to17 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_18to19 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_20 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_21 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_22to24 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_25to29 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_30to34 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_35to39 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_40to44 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_45to49 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_50to54 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_55to59 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_60to61 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_62to64 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_65to66 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_67to69 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_70to74 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_75to79 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_80to84 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_ge85 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_lt5 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_5to9 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_10to14 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_15to17 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_18to19 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_20 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_21 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_22to24 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_25to29 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_30to34 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_35to39 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_40to44 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_45to49 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_50to54 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_55to59 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_60to61 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_62to64 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_65to66 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_67to69 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_70to74 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_75to79 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_80to84 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_ge85 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>state_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> states<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> zctas <span style="color: #66cc66;">&#40;</span>
	id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	zcta TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_longitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_latitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_lt5 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_5to9 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_10to14 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_15to17 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_18to19 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_20 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_21 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_22to24 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_25to29 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_30to34 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_35to39 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_40to44 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_45to49 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_50to54 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_55to59 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_60to61 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_62to64 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_65to66 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_67to69 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_70to74 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_75to79 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_80to84 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_male_ge85 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_total <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_lt5 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_5to9 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_10to14 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_15to17 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_18to19 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_20 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_21 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_22to24 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_25to29 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_30to34 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_35to39 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_40to44 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_45to49 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_50to54 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_55to59 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_60to61 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_62to64 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_65to66 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_67to69 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_70to74 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_75to79 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_80to84 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	population_female_ge85 <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> states_zctas <span style="color: #66cc66;">&#40;</span>
	state_id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	zcta_id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>state_id<span style="color: #66cc66;">,</span> zcta_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>state_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> states<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>zcta_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> zctas<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- need an index on (state_id, zcta_id) and (zcta_id, state_id)</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">INDEX</span> states_zctas_index2 <span style="color: #993333; font-weight: bold;">ON</span> states_zctas<span style="color: #66cc66;">&#40;</span>zcta_id<span style="color: #66cc66;">,</span> state_id<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>I haven&#8217;t changed a lot, but a few things have changed. First, note the <code>states_zctas</code> table which now accounts for the many-to-many relationship between states and ZCTAs. I&#8217;ve also renamed the population fields in the tables. <code>*_population</code> is now <code>population_*</code> for clarity reasons.</p>
<p>Accessing data is a little trickier as an <code>INNER JOIN</code> is required. For example, to access the total population for each ZCTA in Iowa, this query does the trick:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> zctas<span style="color: #66cc66;">.</span>zcta<span style="color: #66cc66;">,</span> zctas<span style="color: #66cc66;">.</span>population_total
<span style="color: #993333; font-weight: bold;">FROM</span> zctas<span style="color: #66cc66;">,</span> states
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> states_zctas
	<span style="color: #993333; font-weight: bold;">ON</span> states_zctas<span style="color: #66cc66;">.</span>zcta_id<span style="color: #66cc66;">=</span>zctas<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AND</span> states_zctas<span style="color: #66cc66;">.</span>state_id<span style="color: #66cc66;">=</span>states<span style="color: #66cc66;">.</span>id
<span style="color: #993333; font-weight: bold;">WHERE</span> states<span style="color: #66cc66;">.</span>state<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Iowa&quot;</span>;</pre></td></tr></table></div>

<p><strong>Download:</strong> <a title="2010CensusPopulation.7z" href="http://www.gfairchild.com/public/2010CensusPopulation.7z">2010CensusPopulation.7z</a> (size: 3mb)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2011/12/20/update-to-2010-census-sqlite-population-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Note to self: Mercurial doesn&#8217;t like big files</title>
		<link>http://www.gfairchild.com/2011/12/14/note-to-self-mercurial-doesnt-like-big-files/</link>
		<comments>http://www.gfairchild.com/2011/12/14/note-to-self-mercurial-doesnt-like-big-files/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 19:23:27 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=354</guid>
		<description><![CDATA[I recently decided to try Mercurial for version control. I&#8217;m most familiar with Subversion, but I like the idea of a distributed version control system. I tried Git first, but my desktop runs Windows 7, and the Windows interface for Git (TortoiseGit) is a little wonky compared to its SVN brother (TortoiseSVN). I stumbled onto [...]]]></description>
				<content:encoded><![CDATA[<p>I recently decided to try <a href="http://mercurial.selenic.com/" title="Mercurial">Mercurial</a> for version control. I&#8217;m most familiar with <a href="http://subversion.tigris.org/" title="Subversion">Subversion</a>, but I like the idea of a distributed version control system. I tried <a href="http://git-scm.com/" title="Git">Git</a> first, but my desktop runs Windows 7, and the Windows interface for Git (<a href="http://code.google.com/p/tortoisegit/" title="TortoiseGit">TortoiseGit</a>) is a little wonky compared to its SVN brother (<a href="http://tortoisesvn.net/" title="TortoiseSVN">TortoiseSVN</a>). I stumbled onto Mercurial as an alternative to Git, and I love it. The Windows interface (<a href="http://tortoisehg.bitbucket.org/" title="TortoiseHg">TortoiseHg</a>) is great; I actually like it better than TortoiseSVN!</p>
<p>Anyway, my initial repo size was 3.8gb. I pushed it, and after several hours of uploading, I got this error message:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
abort: unexpected response: empty string
[command returned code 255 Mon Dec 12 07:19:00 2011]</pre></td></tr></table></div>

<p>I figured something happened during the transfer, so I wiped the repo and tried again but got the same error message. After some Google-fu attempts, I discovered that this error doesn&#8217;t seem very popular. I figured it might just be choking on the repo size, so I went through and deleted a bunch of data I didn&#8217;t need. I got it down to 1.9gb. I tried again and got the same error message.</p>
<p>At this point, I was starting to get pissed. Pushing a repo that large on a connection with 2mbit upload takes a while, and this was wasting a bunch of time (and bandwidth). I decided to try breaking down the push into several smaller pushes (each around 400-500mb). This worked for the first several pushes, but by push 4, I got the same error. Looking at the files I was pushing, I saw that one of the files was a 500mb ZIP file. I figured this might be the issue, and since I didn&#8217;t actually need the file, I decided to get rid of it and try again. I wiped the repo and tried once more to push the entire repo in one go. Voilà, it worked!</p>
<p>So what was the problem? After looking around, I stumbled onto <a href="http://mercurial.selenic.com/wiki/HandlingLargeFiles" title="http://mercurial.selenic.com/wiki/HandlingLargeFiles">http://mercurial.selenic.com/wiki/HandlingLargeFiles</a> which describes how Mercurial handles large files. Specifically, this sentence described my issue:</p>
<blockquote><p>all files are currently handled as single Python strings <strong>in memory</strong></p></blockquote>
<p>Well of course! I use <a href="http://www.linode.com/" title="Linode">Linode</a> for hosting, and I have the Linode 512 option. Since Mercurial requires memory proportional the the size of the file it&#8217;s processing, I ran out of memory (both physical and swap). I&#8217;m certain a server with more memory could&#8217;ve handled the troublesome 500mb ZIP file with ease, but mine couldn&#8217;t.</p>
<p>So the moral of the story is this: Mercurial is awesome as long as you recognize its memory limits when it comes to large files. If you get the &#8220;empty string&#8221; error 255 on a push, make sure you have enough memory to handle the largest files in your repo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2011/12/14/note-to-self-mercurial-doesnt-like-big-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2010 Census SQLite Database</title>
		<link>http://www.gfairchild.com/2011/12/13/2010-census-sqlite-database/</link>
		<comments>http://www.gfairchild.com/2011/12/13/2010-census-sqlite-database/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 06:50:49 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.gfairchild.com/?p=320</guid>
		<description><![CDATA[In a previous post, I described an SQLite database I generated containing 2000 US Census data population info. Now that the 2010 Census data are out, I decided to update this database. The 2010 Census data are nice and clean (much better than the 2000 data!), but in order to get access to all of [...]]]></description>
				<content:encoded><![CDATA[<p>In a <a href="http://www.gfairchild.com/2011/02/26/new-kml-population-updates/" title="previous post">previous post</a>, I described an SQLite database I generated containing 2000 US Census data population info. Now that the 2010 Census data are out, I decided to update this database. The 2010 Census data are nice and clean (<em>much</em> better than the 2000 data!), but in order to get access to all of the data I&#8217;ve generated here, you need lots of different files, and it&#8217;s kind of a pain to combine it all into a simple useable format (I&#8217;ve spent the better part of an entire day doing it, and I&#8217;m working on a PhD in computer science&#8230;). Hopefully, this&#8217;ll make someone&#8217;s life simpler.</p>
<p>First, the data I used to generate this database can be found in two places:</p>
<ul>
<li><a href="http://factfinder2.census.gov/" title="U.S. Census Bureau American FactFinder 2">U.S. Census Bureau American FactFinder 2</a> &#8211; This is where I got all the population info.</li>
<li><a href="http://www.census.gov/geo/www/tiger/shp.html" title="U.S. Census Bureau TIGER/Line® Shapefiles">U.S. Census Bureau TIGER/Line® Shapefiles</a> &#8211; I used the shapefiles to extract the centroids of each geographic unit.</li>
</ul>
<p>The data I present here contain state, county, and ZCTA (which is mostly the same as ZIP code) population info for every state in the United States plus Puerto Rico and Washington DC. I provide centroids (latitude, longitude) and population by age/sex for each geographic unit. This is the schema I used to create the database:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> states <span style="color: #66cc66;">&#40;</span>
	id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	state TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_longitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_latitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_lt5_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_5to9_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_10to14_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_15to17_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_18to19_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_20_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_21_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_22to24_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_25to29_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_30to34_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_35to39_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_40to44_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_45to49_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_50to54_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_55to59_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_60to61_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_62to64_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_65to66_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_67to69_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_70to74_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_75to79_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_80to84_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_ge85_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_lt5_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_5to9_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_10to14_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_15to17_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_18to19_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_20_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_21_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_22to24_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_25to29_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_30to34_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_35to39_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_40to44_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_45to49_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_50to54_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_55to59_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_60to61_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_62to64_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_65to66_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_67to69_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_70to74_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_75to79_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_80to84_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_ge85_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> counties <span style="color: #66cc66;">&#40;</span>
	id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	state_id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	county TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_longitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_latitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_lt5_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_5to9_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_10to14_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_15to17_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_18to19_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_20_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_21_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_22to24_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_25to29_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_30to34_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_35to39_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_40to44_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_45to49_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_50to54_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_55to59_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_60to61_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_62to64_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_65to66_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_67to69_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_70to74_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_75to79_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_80to84_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_ge85_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_lt5_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_5to9_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_10to14_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_15to17_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_18to19_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_20_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_21_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_22to24_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_25to29_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_30to34_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_35to39_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_40to44_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_45to49_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_50to54_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_55to59_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_60to61_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_62to64_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_65to66_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_67to69_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_70to74_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_75to79_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_80to84_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_ge85_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>state_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> states<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> zctas <span style="color: #66cc66;">&#40;</span>
	id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	state_id <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	zcta TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_longitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	centroid_latitude <span style="color: #993333; font-weight: bold;">REAL</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_lt5_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_5to9_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_10to14_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_15to17_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_18to19_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_20_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_21_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_22to24_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_25to29_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_30to34_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_35to39_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_40to44_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_45to49_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_50to54_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_55to59_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_60to61_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_62to64_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_65to66_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_67to69_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_70to74_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_75to79_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_80to84_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	male_ge85_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_total_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_lt5_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_5to9_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_10to14_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_15to17_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_18to19_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_20_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_21_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_22to24_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_25to29_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_30to34_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_35to39_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_40to44_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_45to49_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_50to54_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_55to59_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_60to61_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_62to64_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_65to66_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_67to69_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_70to74_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_75to79_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_80to84_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	female_ge85_population <span style="color: #993333; font-weight: bold;">INTEGER</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>state_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> states<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Previously, I included boundary data (done very poorly as I made several mistakes regarding ZCTAs with multiple boundaries and ZCTAs present in multiple states). I also provided KML files containing this data. I&#8217;ve chosen not to do either of these with the 2010 data. All I provide here are population stats and the centroid for each geographic unit. It&#8217;s trivial to convert TIGER/Line® shapefiles to KML using free tools (such as <a href="http://www.qgis.org/" title="QuantumGIS">QuantumGIS</a>), and using the SQLite database I provide, it&#8217;d be fairly simple to add population attributes. Plus, it&#8217;s not super practical to use a KML file for attribute accesses; an SQLite database makes much more sense (and is <em>much</em> faster).</p>
<p>Without further ado:<br />
<strong>Download:</strong> <a href="http://www.gfairchild.com/public/2010CensusPopulation.7z" title="2010CensusPopulation.7z">2010CensusPopulation.7z</a> (size: 2.9mb)</p>
<p>You&#8217;ll need a program like <a href="http://www.7-zip.org/" title="7-Zip">7-Zip</a> to extract the database. You can use a number of free programs to view the data (my favorite for Windows is <a href="http://www.sqliteexpert.com/" title="SQLite Expert">SQLite Expert</a>).</p>
<p>Feel free to contact me with any questions or comments you may have regarding this database. Hope you find it useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2011/12/13/2010-census-sqlite-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>logrotate: Use it!</title>
		<link>http://www.gfairchild.com/2011/09/05/logrotate-use-it/</link>
		<comments>http://www.gfairchild.com/2011/09/05/logrotate-use-it/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 20:13:03 +0000</pubDate>
		<dc:creator>Geoff</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Website]]></category>

		<guid isPermaLink="false">http://www.fangsoft.net/?p=308</guid>
		<description><![CDATA[I was digging through my virtual hosts looking at log files and noticed that a few of them had pretty massive access logs. One of the more popular sites I run for some friends, American K-Pop Fans, had an access log of 363mb, and I&#8217;ve only been running the site for a few weeks! That [...]]]></description>
				<content:encoded><![CDATA[<p>I was digging through my virtual hosts looking at log files and noticed that a few of them had pretty massive access logs. One of the more popular sites I run for some friends, <a title="American K-Pop Fans" href="http://americankpopfans.com/">American K-Pop Fans</a>, had an access log of 363mb, and I&#8217;ve only been running the site for a few weeks! That obviously wasn&#8217;t going to work, so I started looking up how to manage log files. I noticed that Apache seemed to do an awesome job of keeping logs organized in <code>/var/log/apache2/</code> and figured I should be able to model my log cleanliness after them.</p>
<p>After some Googling, I stumbled onto <a href="http://httpd.apache.org/docs/2.2/programs/rotatelogs.html" title="rotatelogs">rotatelogs</a>. After fumbling with it, although it&#8217;s pretty cool, I discovered that this wasn&#8217;t quite what I wanted. I did some more Googling and discovered <a href="http://linuxcommand.org/man_pages/logrotate8.html" title="logrotate">logrotate</a>, a program built into Linux for managing large amounts of logs. The two almost identical names confused me at first, but the difference became clear pretty fast.</p>
<p><code>rotatelogs</code> is a really simple program for automatically breaking log files apart when Apache adds an entry. It does this by piping the log file entry through the program which then decides if it needs to create a new log file or can use the existing one. You can choose when to create a new log file based on time or log size. <code>logrotate</code>, on the other hand, is a Linux command-line utility which runs as a cron job every day. It runs all scripts in <code>/etc/logrotate.d/</code>. Looking in that directory, there&#8217;s an <code>apache2</code> script which keeps Apache&#8217;s log files nice and tidy. There are also a variety of others, depending on what&#8217;s installed.</p>
<p>Both <a href="http://library.linode.com/linux-tools/utilities/logrotate" title="Linode's logrotate article">Linode&#8217;s logrotate article</a> and <a href="http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-ubuntu-part-1" title="Slicehost's logrotate article">Slicehost&#8217;s logrotate article</a> helped me setup <code>logrotate</code> for my virtualhosts. Here&#8217;s what mine looks like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="" style="font-family:monospace;">/srv/www/*/logs/*.log <span class="br0">&#123;</span>
	rotate <span style="">14</span>
	daily
	compress
	delaycompress
	sharedscripts
	postrotate
		/usr/sbin/apache2ctl graceful &gt; /dev/null
	endscript
<span class="br0">&#125;</span></pre></td></tr></table></div>

<p>The idea is pretty simple. Line by line:</p>
<ol>
<li>I list all of my virtual host log paths. All of my virtual hosts follow the same directory structure, so I can get away with wildcard usage like this.</li>
<li>I tell it that I want to keep 14 days of previous log files.</li>
<li>I tell it that I want it to run daily.</li>
<li>I tell it that I want old log files compressed to save space.</li>
<li>I tell it that it should delay compressing the most recent archived log file.</li>
<li>I tell it that all of the virtual hosts listed on line 1 should be processed <em>before</em> the following script runs.</li>
<li>I tell it to restart Apache gracefully (no open connections will be closed, and old log files won&#8217;t be closed immediately). The reason we use <code>delaycompress</code> is because we don&#8217;t want to compress the most recent log file until we&#8217;re sure Apache is done with it.</li>
</ol>
<p>That&#8217;s it! This simple script maintains all my log files for me so that I don&#8217;t have to worry about them growing out of control.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gfairchild.com/2011/09/05/logrotate-use-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using apc
Database Caching using apc
Object Caching 960/1079 objects using apc

 Served from: www.gfairchild.com @ 2013-05-24 15:59:06 by W3 Total Cache -->