<?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>Record count &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/record-count/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>Wed, 22 Feb 2017 20:27:34 +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: Shell script to store psql SELECT output into Variable</title>
		<link>https://www.dbrnd.com/2017/03/postgresql-shell-script-to-store-psql-select-output-into-variable/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 01 Mar 2017 16:16:54 +0000</pubDate>
				<category><![CDATA[Bash Shell Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Linux Variable]]></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 Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<category><![CDATA[Record count]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[Tuple]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4666</guid>

					<description><![CDATA[In the previous post, I shared shell script like store psql result into record array. In this post, I am sharing one more shell script to store the result of psql SELECT query into a Variable of Bash Shell Script. This handy script is useful for a beginner who just started to write a PostgreSQL [&#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%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" 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%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" 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%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" 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%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" 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%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" 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%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" 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%2F2017%2F03%2Fpostgresql-shell-script-to-store-psql-select-output-into-variable%2F&#038;title=PostgreSQL%3A%20Shell%20script%20to%20store%20psql%20SELECT%20output%20into%20Variable" data-a2a-url="https://www.dbrnd.com/2017/03/postgresql-shell-script-to-store-psql-select-output-into-variable/" data-a2a-title="PostgreSQL: Shell script to store psql SELECT output into Variable"></a></p><p>In the previous post, I shared shell script like store psql result into record array.<br />
In this post, I am sharing one more shell script to store the result of psql SELECT query into a Variable of Bash Shell Script. </p>
<p>This handy script is useful for a beginner who just started to write a PostgreSQL DBA Bash Shell Script. You need this kind of demonstration to store the result of psql query into variable mostly like count of records. </p>
<p>The value of this variable we can use for further validation something like data exists or not in the Table.</p>
<blockquote><p>In the below script, I used two variables to store the count of a table, but do not forget to notice option &#8216;-t&#8217; in the second query which returns only tuple value and without option &#8216;-t&#8217; it returns all formatted text as well like column name, returned a row count. </p>
<p>We need only tuple value so we must use &#8216;-t&#8217; option. Please check the below demonstration.
</p></blockquote>
<pre class="crayon-plain-tag">#!/bin/bash

DB_NAME=$1
RecordCount1=$( psql -d ${DB_NAME} -c "select count(1) from tbl_students" )
RecordCount2=$( psql -d ${DB_NAME} -t -c "select count(1) from tbl_students" )

echo "RecordCount1:"$RecordCount1
echo "RecordCount2:"$RecordCount2</pre> </p>
<p><strong>The result:</strong></p>
<pre class="crayon-plain-tag">RecordCount1: count ------- 9 (1 row)
RecordCount2: 9</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
