<?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>youdidwhatwithtsql.com &#187; ODBC</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/odbc/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:21:23 +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>Postgres Linked Server How To</title>
		<link>http://www.youdidwhatwithtsql.com/postgres-linked-server-how-to/590</link>
		<comments>http://www.youdidwhatwithtsql.com/postgres-linked-server-how-to/590#comments</comments>
		<pubDate>Sat, 30 Jan 2010 16:44:07 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Linked Server]]></category>
		<category><![CDATA[ODBC]]></category>
		<category><![CDATA[Postgres]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/postgres-linked-server-how-to/590</guid>
		<description><![CDATA[Just a quick post showing how to add a Postgres database server as a Linked Server in Microsoft&#160;SQL Server. Install the psqlODBC driver for Windows. Control Panel &#62; Administrative Tools &#62; Data Sources (ODBC). Click the &#34;System DSN&#34; tab and click the Add button. Choose &#34;PostreSQL ANSI&#34; and click Finish. Configure the data source by [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/postgres-linked-server-how-to/590">Postgres Linked Server How To</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Just a quick post showing how to add a <a href="http://www.postgresql.org/" target="_blank">Postgres</a> database server as a <a href="http://msdn.microsoft.com/en-us/library/ms188279.aspx" target="_blank">Linked Server</a> in <a href="http://www.microsoft.com/en/us/default.aspx" target="_blank">Microsoft</a>&#160;<a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a>.</p>
<ul>
<li>Install the <a href="http://www.postgresql.org/ftp/odbc/versions/" target="_blank">psqlODBC</a> driver for Windows. </li>
<li>Control Panel &gt; Administrative Tools &gt; Data Sources (ODBC). </li>
<li>Click the &quot;System DSN&quot; tab and click the Add button. </li>
</ul>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/01/new_data_source.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Create New Data Source Dialog" border="0" alt="new data source thumb Postgres Linked Server How To" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/01/new_data_source_thumb.png" width="644" height="483" /></a> </p>
<ul>
<li>Choose &quot;PostreSQL ANSI&quot; and click Finish. </li>
<li>Configure the data source by entering the server, username, password and database details. </li>
</ul>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/01/Postgres_ODBC_Setup.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Postgres ODBC Setup" border="0" alt="Postgres ODBC Setup thumb Postgres Linked Server How To" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/01/Postgres_ODBC_Setup_thumb.png" width="644" height="367" /></a> </p>
</p>
<ul>
<li>Click &quot;Test&quot; to confirm the data source functions. If it fails ensure that <a href="http://www.postgresql.org/" target="_blank">Postgres</a> is running and check your configuration details. </li>
<li>Click &quot;Save&quot; and then &quot;OK&quot; once successful. </li>
<li>Fire up <a href="http://msdn.microsoft.com/en-us/library/ms174173.aspx" target="_blank">SSMS</a> and run the following <a href="http://en.wikipedia.org/wiki/Transact-SQL" target="_blank">T-SQL</a> to create the Linked Server to Postgres. </li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p590code3'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5903"><td class="code" id="p590code3"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> <span style="color: #808080;">&#91;</span>master<span style="color: #808080;">&#93;</span>
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_addlinkedserver</span> @server <span style="color: #808080;">=</span> N<span style="color: #FF0000;">'POSTGRES'</span>, @srvproduct<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'Postgres'</span>, @provider<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'MSDASQL'</span>, @datasrc<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'PostgreSQL30'</span>
&nbsp;
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_serveroption</span> @server<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'POSTGRES'</span>, @optname<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'collation compatible'</span>, @optvalue<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'false'</span>
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_serveroption</span> @server<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'POSTGRES'</span>, @optname<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'data access'</span>, @optvalue<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'true'</span>
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_serveroption</span> @server<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'POSTGRES'</span>, @optname<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'rpc'</span>, @optvalue<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'false'</span>
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_serveroption</span> @server<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'POSTGRES'</span>, @optname<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'rpc out'</span>, @optvalue<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'false'</span>
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_serveroption</span> @server<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'POSTGRES'</span>, @optname<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'connect timeout'</span>, @optvalue<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'0'</span>
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_serveroption</span> @server<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'POSTGRES'</span>, @optname<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'collation name'</span>, @optvalue<span style="color: #808080;">=</span>null
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_serveroption</span> @server<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'POSTGRES'</span>, @optname<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'query timeout'</span>, @optvalue<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'0'</span>
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_serveroption</span> @server<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'POSTGRES'</span>, @optname<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'use remote collation'</span>, @optvalue<span style="color: #808080;">=</span>N<span style="color: #FF0000;">'true'</span>
GO
<span style="color: #0000FF;">USE</span> <span style="color: #808080;">&#91;</span>master<span style="color: #808080;">&#93;</span>
GO
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_addlinkedsrvlogin</span> @rmtsrvname <span style="color: #808080;">=</span> N<span style="color: #FF0000;">'POSTGRES'</span>, @locallogin <span style="color: #808080;">=</span> <span style="color: #808080;">NULL</span> , @useself <span style="color: #808080;">=</span> N<span style="color: #FF0000;">'False'</span>
GO</pre></td></tr></table></div>

<p>Alternatively copy the below configuration in SSMS. The most critical thing here is to get the setting for &quot;Data source&quot; correct. This should be the name of the System DSN you added earlier.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/01/Postgres_Linked_Server_Configuration.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Postgres Linked Server Configuration" border="0" alt="Postgres Linked Server Configuration thumb Postgres Linked Server How To" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/01/Postgres_Linked_Server_Configuration_thumb.png" width="539" height="484" /></a> </p>
<ul>
<li>Finally execute the query below. This uses <a href="http://technet.microsoft.com/en-us/library/ms188427.aspx" target="_blank">OPENQUERY</a> and will list all the tables in your <a href="http://www.postgresql.org/" target="_blank">Postgres</a> system database. </li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p590code4'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5904"><td class="code" id="p590code4"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> <span style="color: #0000FF;">OPENQUERY</span><span style="color: #808080;">&#40;</span>POSTGRES, <span style="color: #FF0000;">'SELECT * FROM INFORMATION_SCHEMA.TABLES'</span><span style="color: #808080;">&#41;</span>;</pre></td></tr></table></div>

<p>If everything is running correctly you should see something like below.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/01/postgres_openquery_result.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Postgres openquery result" border="0" alt="postgres openquery result thumb Postgres Linked Server How To" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/01/postgres_openquery_result_thumb.png" width="644" height="211" /></a></p>
<p><map name='google_ad_map_590_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/590?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_590_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=590&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fpostgres-linked-server-how-to%2F590' title="Postgres Linked Server How To" alt=" Postgres Linked Server How To" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/postgres-linked-server-how-to/590">Postgres Linked Server How To</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/postgres-linked-server-how-to/590" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/postgres-linked-server-how-to/590/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

