LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2017, 03:55 AM   #1
slayer_1994
Member
 
Registered: Feb 2017
Posts: 38

Rep: Reputation: Disabled
Count for .sql qurery


Hi There

Just created a .sql script and executes fine, it comes back with two lines of results, I was wondering is there a way of adding up the two results to get a round number. I tired wc -l but that didn't work.

Many Thanks for your help

Code:
Code:
psql -t -f /opt/ca/SAP_Tooling/sql/self_monitoring/check_number_of_open_connections_database.sql
The result is:
Quote:
34 | idle
1 | active
The SQL query:
Quote:
select count(*), state from pg_stat_activity group by state;
\q
Is there any way of adding those two numbers to get a whole round number of users as in 35.
 
Old 03-29-2017, 04:46 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Not sure if this will work but try:

Code:
select count(*), state from pg_stat_activity group by state WITH ROLLUP;
 
Old 03-29-2017, 04:48 AM   #3
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
probably awk... thinking something like

Code:
 | awk '{users += $1} END {print users}'
haven't tested it myself tho.
 
1 members found this post helpful.
Old 03-29-2017, 05:03 AM   #4
slayer_1994
Member
 
Registered: Feb 2017
Posts: 38

Original Poster
Rep: Reputation: Disabled
Hi Guys

Thanks for the responses

@TenTenths - no unfortunately that didn't work - psql:/opt/ca/SAP_Tooling/sql/self_monitoring/check_number_of_open_connections_database.sql:1: ERROR: syntax error at or near "WITH ROLLUP"

@r3sistance - Yes that worked great thank you.
 
Old 03-29-2017, 05:05 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by slayer_1994 View Post
@TenTenths - no unfortunately that didn't work -
Ah, would have worked with MySQL but obviously not with PSQL

Glad you got sorted by the other method though.
 
1 members found this post helpful.
  


Reply

Tags
count, newbie, shell script, sql, unix



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] MySql order by COUNT and list the total count countrydj Programming 3 07-19-2012 12:21 PM
Warning: [fnn_insert] Column count doesn't match value count at row 1 in bondoq Programming 2 09-27-2011 04:11 PM
DBD::mysql::st execute failed: Column count doesn't match value count at row 1 shifter Programming 2 02-24-2010 07:42 PM
sql - select, count, join, group true_atlantis Programming 1 11-19-2008 10:07 PM
Should posts in general count on your post count? Joey.Dale General 16 01-27-2004 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration