<?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>RETURNS TABLE &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/returns-table/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>Sun, 27 Nov 2016 17:28:08 +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: Performance Test of RETURNS TABLE vs OUT Parameters</title>
		<link>https://www.dbrnd.com/2016/11/postgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 26 Nov 2016 17:27:32 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[OUT Parameters]]></category>
		<category><![CDATA[Performance Test]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[RETURNS TABLE]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3927</guid>

					<description><![CDATA[One of our PostgreSQL database developers asked one question: What is the performance difference between RETURNS TABLE and OUT parameters? My simple answer was, no major difference between these two, but RETURNS TABLE is quite faster, easy to write, clear to everyone. I have prepared two different function one is &#8220;plpgsql&#8221; and the other is [&#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%2F2016%2F11%2Fpostgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record%2F&amp;linkname=PostgreSQL%3A%20Performance%20Test%20of%20RETURNS%20TABLE%20vs%20OUT%20Parameters" 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%2F2016%2F11%2Fpostgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record%2F&amp;linkname=PostgreSQL%3A%20Performance%20Test%20of%20RETURNS%20TABLE%20vs%20OUT%20Parameters" 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%2F2016%2F11%2Fpostgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record%2F&amp;linkname=PostgreSQL%3A%20Performance%20Test%20of%20RETURNS%20TABLE%20vs%20OUT%20Parameters" 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%2F2016%2F11%2Fpostgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record%2F&amp;linkname=PostgreSQL%3A%20Performance%20Test%20of%20RETURNS%20TABLE%20vs%20OUT%20Parameters" 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%2F2016%2F11%2Fpostgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record%2F&amp;linkname=PostgreSQL%3A%20Performance%20Test%20of%20RETURNS%20TABLE%20vs%20OUT%20Parameters" 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%2F2016%2F11%2Fpostgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record%2F&amp;linkname=PostgreSQL%3A%20Performance%20Test%20of%20RETURNS%20TABLE%20vs%20OUT%20Parameters" 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%2F2016%2F11%2Fpostgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record%2F&#038;title=PostgreSQL%3A%20Performance%20Test%20of%20RETURNS%20TABLE%20vs%20OUT%20Parameters" data-a2a-url="https://www.dbrnd.com/2016/11/postgresql-performance-test-of-returns-table-vs-out-parameters-plpgsql-sql-return-query-setof-record/" data-a2a-title="PostgreSQL: Performance Test of RETURNS TABLE vs OUT Parameters"></a></p><p>One of our PostgreSQL database developers asked one question: What is the performance difference between RETURNS TABLE and OUT parameters?</p>
<p>My simple answer was, no major difference between these two, but RETURNS TABLE is quite faster, easy to write, clear to everyone. </p>
<p>I have prepared two different function one is &#8220;plpgsql&#8221; and the other is &#8220;sql&#8221; language. </p>
<p>You can access this demonstration and compare the performance report in your Postgres Environment. </p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_ItemTransactions 
 (
     TranID SERIAL
     ,TransactionDate TIMESTAMP WITHOUT TIME ZONE
     ,TransactionName TEXT
 );

INSERT INTO tbl_ItemTransactions 
(TransactionDate, TransactionName)
SELECT x, 'dbrnd' 
FROM generate_series('2016-01-01 00:00:00', '2016-12-31 00:00:00','2 seconds'::interval) a(x);</pre> </p>
<p><strong>Create a function to test RETURN TABLE:</strong></p>
<pre class="crayon-plain-tag">CREATE OR REPLACE FUNCTION fn_TestReturnTable(InTransactionDate TIMESTAMP WITHOUT TIME ZONE)
RETURNS TABLE(OutTranID INTEGER)
AS
$dbrnd$
BEGIN
	RETURN QUERY
	SELECT TranID
	FROM tbl_ItemTransactions 
	WHERE TransactionDate &gt; InTransactionDate; 
END;
$dbrnd$
LANGUAGE 'plpgsql';</pre> </p>
<p><strong>Sample Execution:</strong></p>
<pre class="crayon-plain-tag">EXPLAIN ANALYZE
SELECT *FROM fn_TestReturnTable ('2016-06-01');</pre> </p>
<p><strong>Performance Report: </strong></p>
<pre class="crayon-plain-tag">"Function Scan on fn_testreturntable  
(cost=0.25..10.25 rows=1000 width=4) 
(actual time=13390.371..31899.698 rows=9201600 loops=1)"
"Planning time: 0.047 ms"
"Execution time: 43660.453 ms"</pre> </p>
<p><strong>Create a function to test the OUT parameter:</strong></p>
<pre class="crayon-plain-tag">CREATE OR REPLACE FUNCTION fn_TestOutParameter
(
	InTransactionDate TIMESTAMP WITHOUT TIME ZONE
	,OUT OutTranID INTEGER
)
RETURNS SETOF INT
AS
$dbrnd$

	SELECT TranID::INTEGER
	FROM tbl_ItemTransactions 
	WHERE TransactionDate &gt; InTransactionDate; 
$dbrnd$
LANGUAGE 'sql';</pre> </p>
<p><strong>Sample Execution:</strong></p>
<pre class="crayon-plain-tag">EXPLAIN ANALYZE
SELECT *FROM fn_TestOutParameter ('2016-06-01');</pre> </p>
<p><strong>Performance Report:</strong></p>
<pre class="crayon-plain-tag">"Function Scan on fn_testoutparameter  
(cost=0.25..10.25 rows=1000 width=4) 
(actual time=12698.673..31794.391 rows=9201600 loops=1)"
"Planning time: 0.055 ms"
"Execution time: 47854.064 ms"</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
