<?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>RAISE NOTICE &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/raise-notice/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, 16 Apr 2018 18:21:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>PostgreSQL: Use RAISE Statements to debug your Query and Function performance</title>
		<link>https://www.dbrnd.com/2018/04/postgresql-use-raise-statements-to-debug-your-query-and-function-performance/</link>
					<comments>https://www.dbrnd.com/2018/04/postgresql-use-raise-statements-to-debug-your-query-and-function-performance/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 14 Apr 2018 16:16:15 +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[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[Query Debugging]]></category>
		<category><![CDATA[RAISE EXCEPTION]]></category>
		<category><![CDATA[RAISE INFO]]></category>
		<category><![CDATA[RAISE NOTICE]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4253</guid>

					<description><![CDATA[You can use the RAISE Statements for the report messages and raise errors. Different level of RAISE statements are INFO, NOTICE, and EXCEPTION. By default, NOTICE is always returning to the client only. We should use RAISE INFO for our internal query or function debugging. We should break down our code into smaller parts and [&#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%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" 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%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" 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%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" 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%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" 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%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" 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%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&amp;linkname=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" 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%2F2018%2F04%2Fpostgresql-use-raise-statements-to-debug-your-query-and-function-performance%2F&#038;title=PostgreSQL%3A%20Use%20RAISE%20Statements%20to%20debug%20your%20Query%20and%20Function%20performance" data-a2a-url="https://www.dbrnd.com/2018/04/postgresql-use-raise-statements-to-debug-your-query-and-function-performance/" data-a2a-title="PostgreSQL: Use RAISE Statements to debug your Query and Function performance"></a></p><p>You can use the RAISE Statements for the report messages and raise errors.<br />
Different level of RAISE statements are INFO, NOTICE, and EXCEPTION.</p>
<p>By default, NOTICE is always returning to the client only. We should use RAISE INFO for our internal query or function debugging. </p>
<p>We should break down our code into smaller parts and add RAISE statement with clock_timestamp(). </p>
<p>We can compare the execution time difference between the code blocks and can find a slow running code block.<br />
We can also add parameter and variable to the RAISE statement. We can print the current value of our parameter and variable.</p>
<p><strong>Few examples: </strong></p>
<pre class="crayon-plain-tag">RAISE INFO 'Hello World !';
RAISE NOTICE '%', variable_name;
RAISE NOTICE 'Current value of parameter (%)', my_var;
RAISE EXCEPTION '% cannot have null salary', EmpName;</pre> </p>
<p><strong>One Practical Demonstration:</strong></p>
<p><strong>Create a table with Sample Data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE Employee
(
	 EmpID SERIAL
	 ,EmpName CHARACTER VARYING(50)
	 ,Gender CHAR(1)
	 ,AGE SMALLINT
);
INSERT INTO Employee 
(
	 EmpName 
	 ,Gender 
	 ,AGE 
)
VALUES 
 ('Anvesh','M',27)
 ,('Mohan','M',30)
 ,('Roy','M',31)
 ,('Meera','F',27)
 ,('Richa','F',26)
 ,('Martin','M',35)
 ,('Mahesh','M',38)
 ,('Paresh','M',22)
 ,('Alina','F',21)
 ,('Alex','M',24);</pre> </p>
<p><strong>Sample function for Custome Paging with the use of RAISE:</strong></p>
<pre class="crayon-plain-tag">CREATE OR REPLACE FUNCTION fn_GetEmployeeData
(
	Paging_PageSize INTEGER = NULL
	,Paging_PageNumber INTEGER = NULL   
)
RETURNS TABLE 
( 
	outEmpID INTEGER
	,outEmpName CHARACTER VARYING
	,outGender CHAR(1)
	,outAge SMALLINT
) AS
$BODY$
DECLARE PageNumber BIGINT;
DECLARE TempINT INTEGER;
 
BEGIN
	/* ***************************************************************
	Construct Custom paging parameter...
	**************************************************************** */
	IF (paging_pagesize IS NOT NULL AND paging_pagenumber IS NOT NULL) THEN
		PageNumber := (Paging_PageSize * (Paging_PageNumber-1)); 
	END IF; 

	RAISE INFO '%','Construction of Custom Paging Parameter -  DONE '|| clock_timestamp();
	/* ************************************************
	Custome paging SQL Query construction.......
	************************************************ */
	TempINT := 10000;
	WHILE (TempINT &gt; 0)	
	LOOP		
		TempINT = TempINT - 1;
		RAISE INFO '%','The current value of TempINT ' || TempINT; 
	END LOOP;
	
	RETURN QUERY
	SELECT
		EmpID
		,EmpName
		,Gender
		,Age
	FROM public.Employee
	ORDER BY EmpID
	LIMIT Paging_PageSize
	OFFSET PageNumber; 

	RAISE INFO '%','Final result set of main query -  DONE ' || clock_timestamp(); 
	 
	EXCEPTION WHEN OTHERS THEN 
	RAISE;
END;
$BODY$
LANGUAGE 'plpgsql';</pre> </p>
<p><strong>Execute this function and check the query message window:</strona g><br />
You will find list of RAISE INFO messages that we mentioned in above function.</p>
<pre class="crayon-plain-tag">SELECT *FROM public.fn_GetEmployeeData(4,2);</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/04/postgresql-use-raise-statements-to-debug-your-query-and-function-performance/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
