Have been trying to work out how to return a message if the result is empty.
I am running a select statement as below:
select * from maxIDValue where max_value > 1000000 order by max_value desc;
I am running this in a bash script via psql however the results will be sent out in an email which I have working.
What I want to know is if the results return nothing could I have it so a message is at least inputted instead of (0 rows), even if it was just a message to say there are no Values or something to that extent.
I have tried via bash also: Note: the .sql file is the above query
{
if [ "$( psql -h $SERVERNAME -U test -d Titan -tAf "/home/postgres/tools/testmaxresults.sql" )" = '1' ]
then
psql -h ${SERVERNAME} -U test -d Titan -f /home/postgres/tools/testmaxresults.sql >>${TMPFILE01}
else
echo "No Value Exists" >>${TMPFILE01}
fi
}
To sum up
I want the bash to run the script and if there is data i.e results then run and report (the reporting part works in terms of email etc)
But the select runs and there is 0 results then print/echo "No Values"
I want to run this query against multiple databases. How would I have this enclosed in a bash script so I can run this against each database.
If I run this it only reports the last database as opposed to both.
Any help is appreciated.