<?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>dblink_connect &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/dblink_connect/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 20 Nov 2017 05:54:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>PostgreSQL [Video]: Cross Database Queries using DbLink Extension</title>
		<link>https://www.dbrnd.com/2015/05/postgresql-cross-database-queries-using/</link>
					<comments>https://www.dbrnd.com/2015/05/postgresql-cross-database-queries-using/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 22 May 2015 16:37:08 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL Video]]></category>
		<category><![CDATA[Video Help]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[cross database query]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dblink]]></category>
		<category><![CDATA[dblink_connect]]></category>
		<category><![CDATA[foreign data wrapper]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=184</guid>

					<description><![CDATA[How we can perform cross database queries in PostgreSQL? The different RDBMS systems like Microsoft SQL Server, MySQL, You can select data from one database to another database. What we are doing is we simply select data using database_name.schema.table. In the PostgreSQL, you cannot perform the cross database query like other database technology. In this [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-cross-database-queries-using%2F&amp;linkname=PostgreSQL%20%5BVideo%5D%3A%20Cross%20Database%20Queries%20using%20DbLink%20Extension" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-cross-database-queries-using%2F&amp;linkname=PostgreSQL%20%5BVideo%5D%3A%20Cross%20Database%20Queries%20using%20DbLink%20Extension" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-cross-database-queries-using%2F&amp;linkname=PostgreSQL%20%5BVideo%5D%3A%20Cross%20Database%20Queries%20using%20DbLink%20Extension" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-cross-database-queries-using%2F&amp;linkname=PostgreSQL%20%5BVideo%5D%3A%20Cross%20Database%20Queries%20using%20DbLink%20Extension" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-cross-database-queries-using%2F&amp;linkname=PostgreSQL%20%5BVideo%5D%3A%20Cross%20Database%20Queries%20using%20DbLink%20Extension" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-cross-database-queries-using%2F&amp;linkname=PostgreSQL%20%5BVideo%5D%3A%20Cross%20Database%20Queries%20using%20DbLink%20Extension" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fpostgresql-cross-database-queries-using%2F&#038;title=PostgreSQL%20%5BVideo%5D%3A%20Cross%20Database%20Queries%20using%20DbLink%20Extension" data-a2a-url="https://www.dbrnd.com/2015/05/postgresql-cross-database-queries-using/" data-a2a-title="PostgreSQL [Video]: Cross Database Queries using DbLink Extension"></a></p><p><iframe width="849" height="478" src="https://www.youtube.com/embed/-vk712oS0VM?feature=oembed" frameborder="0" gesture="media" allowfullscreen></iframe></p>
<p><strong>How we can perform cross database queries in PostgreSQL?</strong></p>
<blockquote><p>The different RDBMS systems like Microsoft SQL Server, MySQL, You can select data from one database to another database. What we are doing is we simply select data using database_name.schema.table.<br />
In the PostgreSQL, you cannot perform the cross database query like other database technology.</p></blockquote>
<p>In this post, I am going to demonstrate DbLink extension of PostgreSQL which is used to connect one database to another database.</p>
<blockquote><p>Using DbLink extension, you can perform cross database queries in the PostgreSQL.</p></blockquote>
<p>In this demonstration, I have created two different databases. Respective names &#8220;Database_One&#8221; and &#8220;Database_Two&#8221;.</p>
<blockquote><p>I created one sample table into &#8220;Database_One&#8221; and using DbLink, going to SELECT this table from &#8220;Database_Two&#8221;.<br />
Now, We have to configure DbLink extension in &#8220;Database_Two&#8221;.</p></blockquote>
<p><strong>Below is a full demonstration of this:</strong><br />
<strong>Step 1: Create First sample table and database:</strong></p><pre class="crayon-plain-tag">CREATE DATABASE Database_One;

CREATE TABLE public.tbl_Employee
(
	EmpID INT PRIMARY KEY
	,EmpName CHARACTER VARYING
	,EmpGender CHAR(1)
);

INSERT INTO public.tbl_Employee
VALUES
(1,'Anvesh','M')
,(2,'Neevan','M')
,(3,'Martin','M');</pre><p>
<strong>Step 2: Create Second sample table and database:<br />
</strong></p><pre class="crayon-plain-tag">CREATE DATABASE Database_Two;</pre><p>
<strong>Now, I am going to SELECT Databasee_One data from Database_Two so we have to execute all below scripts on Database_Two to configure DbLink extension for cross database queries.</strong></p>
<hr />
<p><strong>Step 1: Connect to Database_Two:</strong></p>
<p><strong>Step 2: Install / Create DBLink Extenstion:</strong></p><pre class="crayon-plain-tag">CREATE EXTENSION dblink;</pre><p>
<p><strong>Step 3: Verify the system tables of DBLink:</strong></p><pre class="crayon-plain-tag">SELECT pg_namespace.nspname, pg_proc.proname 
FROM pg_proc, pg_namespace 
WHERE pg_proc.pronamespace=pg_namespace.oid 
   AND pg_proc.proname LIKE '%dblink%';</pre><p>
<p><strong>Step 4: Test the connection for Database_One:</strong></p>
<pre class="crayon-plain-tag">SELECT dblink_connect('host=localhost user=dbrnd password=dbrnd dbname=database_one');</pre>
<p><strong>Step 5: Create foreign data wrapper and server for global authentication.<br />
You can use this server object for cross database queries:</strong></p><pre class="crayon-plain-tag">CREATE FOREIGN DATA WRAPPER dbrnd VALIDATOR postgresql_fdw_validator;
CREATE SERVER demodbrnd FOREIGN DATA WRAPPER dbrnd OPTIONS (hostaddr '127.0.0.1', dbname 'database_one');</pre><p>
<p><strong>Step 6: Mapping of user and server:</strong></p><pre class="crayon-plain-tag">CREATE USER MAPPING FOR dbrnd SERVER demodbrnd OPTIONS (user 'dbrnd', password 'dbrnd');</pre><p>
<p><strong>Step 7: Test this server:</strong></p>
<pre class="crayon-plain-tag">SELECT dblink_connect('demodbrnd');</pre>
<p><strong>Step 8: Now, you can SELECT the data of Database_One from Database_Two:</strong></p>
<p>It is creating a virtual table so we have to specify return data type.<br />
<pre class="crayon-plain-tag">SELECT * FROM public.dblink
('demodbrnd','SELECT EmpID,EmpName FROM public.tbl_Employee') 
AS DATA(EmpID INTEGER,EmpName CHARACTER VARYING);</pre>
<p><strong>The Result:</strong><br />
<pre class="crayon-plain-tag">EmpID  |  EmpName
-------------------------
  1    |  "Anvesh"
  2    |  "Neevan"
  3    |  "Martin"</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/05/postgresql-cross-database-queries-using/feed/</wfw:commentRss>
			<slash:comments>38</slash:comments>
		
		
			</item>
	</channel>
</rss>
