<?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>Ryan's Tech Blog &#187; postgresql</title>
	<atom:link href="http://ryepup.unwashedmeme.com/blog/category/postgresql/feed/" rel="self" type="application/rss+xml" />
	<link>http://ryepup.unwashedmeme.com/blog</link>
	<description>mostly tech, mostly rants</description>
	<lastBuildDate>Wed, 04 Jan 2012 03:42:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>working with R, postgresql + SSL, and MSSQL</title>
		<link>http://ryepup.unwashedmeme.com/blog/2010/11/17/working-with-r-postgresql-ssl-and-mssql/</link>
		<comments>http://ryepup.unwashedmeme.com/blog/2010/11/17/working-with-r-postgresql-ssl-and-mssql/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 22:14:03 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[code snippet]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://ryepup.unwashedmeme.com/blog/?p=206</guid>
		<description><![CDATA[I&#8217;ve been able to take a break from my regularly scheduled duties and spend some time working with R.  This is a short log of what I did to get it working. The main things I&#8217;m looking to do is regression modelling from a large dataset I have in postgresql and various stats calculations on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been able to take a break from my regularly scheduled duties and spend some time working with <a href="http://www.r-project.org">R</a>.  This is a short log of what I did to get it working.</p>
<p>The main things I&#8217;m looking to do is regression modelling from a large dataset I have in postgresql and various stats calculations on some business data I have in SQL Server.   Today I got to the stage in my R learning where I wanted to hook up the databases.</p>
<p>My setup:</p>
<ul>
<li>R version 2.12.0 on windows 7</li>
<li>postgresql 8.4.5 on ubuntu server, requiring SSL</li>
<li>MS SQL Server 2005 on Windows 2003</li>
</ul>
<p>R connects to databases via <a href="http://cran.r-project.org/web/packages/RJDBC/index.html">RJDBC</a>, which (surprise) uses JDBC.  You need to download JDBC drivers for each server, and then can load those up inside R.</p>
<ol>
<li>Install RJDBC
<ol>
<li>Open R</li>
<li>Packages -&gt; Install package(s)</li>
<li>pick a mirror near you</li>
<li>select RJDBC</li>
</ol>
</li>
<li>install JDBC driver for MSSQL
<ol>
<li>I used jtds: <a href="http://jtds.sourceforge.net/">http://jtds.sourceforge.net/</a> (there is also a Microsoft provided driver I didn&#8217;t hear about until I was done)</li>
<li>download and unzip</li>
<li>note the path to the jtds jar file (hereafter referred to as $JTDS and the jar filename</li>
<li>open <a href="http://jtds.sourceforge.net/faq.html#driverImplementation">http://jtds.sourceforge.net/faq.html#driverImplementation</a>, which has some magic strings JDBC wants</li>
<li>optional &#8211; copy $JTDS/(x64|x86)/SSO/ntlmauth.dll into your %PATH% if you want to use windows authentication with SQL Server</li>
</ol>
</li>
<li>install JDBC driver for Postgresql
<ol>
<li>Download from <a href="http://jdbc.postgresql.org/">http://jdbc.postgresql.org/</a></li>
<li>note the path to the jar file (hereafter referred to as $PG) and the jar file name</li>
<li>open <a href="http://jdbc.postgresql.org/documentation/head/load.html">http://jdbc.postgresql.org/documentation/head/load.html</a>, which has some magic strings JDBC wants</li>
</ol>
</li>
</ol>
<p>Then, to connect with MSSQL:</p>
<pre>&gt; library(RJDBC)
&gt; mssql &lt;- JDBC("net.sourceforge.jtds.jdbc.Driver", "$JTDS/jtds-1.2.5.jar", "`")
&gt; testdb &lt;- dbConnect(mssql, "jdbc:jtds:sqlserver://host/dbname")
&gt; typeof(dbGetQuery(testdb, "SELECT whathaveyou FROM whither"))
[1] "list"
</pre>
<p>And you&#8217;re off and running with a list of your results in a list and can do whatever you like.</p>
<p>Now for postgresql+ssl:</p>
<pre>&gt; pgsql &lt;- JDBC("org.postgresql.Driver", "$PG/postgresql-9.0-801.jdbc3.jar", "`")
&gt; testdb &lt;- dbConnect(pgsql, "jdbc:postgresql://host/dbname?ssl=true", password="password")
&gt; typeof(dbGetQuery(testdb, "SELECT whathaveyou FROM whither"))
[1] "list"
</pre>
<p>The connection here has a lot more options, and depends highly on your server&#8217;s pg_hba.conf.  It took a little while figure out the &#8220;?ssl=true&#8221; bit.  Luckily you get pretty descriptive error messages if you can&#8217;t connect, and the <a href="http://jdbc.postgresql.org/documentation/head/index.html">PostgreSQL JDBC docs</a> are pretty good.</p>
<p>Now to re-learn everything I once knew about regression modeling!</p>
<p><a href="http://ryepup.unwashedmeme.com/blog/wp-content/uploads/2007/06/worksonmymachine_logo_small.png"><img class="alignnone size-full wp-image-27" title="works on my machine" src="http://ryepup.unwashedmeme.com/blog/wp-content/uploads/2007/06/worksonmymachine_logo_small.png" alt="" width="140" height="64" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ryepup.unwashedmeme.com/blog/2010/11/17/working-with-r-postgresql-ssl-and-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>latest postgres docs bookmarklet</title>
		<link>http://ryepup.unwashedmeme.com/blog/2010/01/28/latest-postgres-docs-bookmarklet/</link>
		<comments>http://ryepup.unwashedmeme.com/blog/2010/01/28/latest-postgres-docs-bookmarklet/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 15:00:55 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://ryepup.unwashedmeme.com/blog/?p=161</guid>
		<description><![CDATA[When using google to find things in the excellent Postgresql documentation, I often end up on pages showing old postgres versions.  For example, googling for &#8220;postgresql create index&#8221;, the first hit is for the postgresql 8.2 docs, and I&#8217;m running 8.4 now.  My co-workers made a greasemonkey script to automatically redirect to the current version, [...]]]></description>
			<content:encoded><![CDATA[<p>When using google to find things in the excellent <a href="http://www.postgresql.org/docs/">Postgresql documentation</a>, I often end up on pages showing old postgres versions.  For example, googling for &#8220;postgresql create index&#8221;, the first hit is for the postgresql 8.2 docs, and I&#8217;m running 8.4 now.  My co-workers made a <a href="http://www.greasespot.net/">greasemonkey </a>script to automatically redirect to the current version, and I adapted that into a bookmarklet.</p>
<p>Drag this link into your address bar to to use it in your browser:</p>
<p><a href="javascript:(function(){window.location = String(window.location).replace(/docs\/[0-9.]+/,&quot;docs/current&quot;);})();">pg-docs</a></p>
<p>When you find yourself on a old postgres docs page, click the bookmarklet to redirect to the latest version of that page.   This should work as long as the postgres folks keep their URL naming scheme.</p>
]]></content:encoded>
			<wfw:commentRss>http://ryepup.unwashedmeme.com/blog/2010/01/28/latest-postgres-docs-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.560 seconds -->

