LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Count for .sql qurery (https://www.linuxquestions.org/questions/linux-newbie-8/count-for-sql-qurery-4175602763/)

slayer_1994 03-29-2017 03:55 AM

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.

TenTenths 03-29-2017 04:46 AM

Not sure if this will work but try:

Code:

select count(*), state from pg_stat_activity group by state WITH ROLLUP;

r3sistance 03-29-2017 04:48 AM

probably awk... thinking something like

Code:

| awk '{users += $1} END {print users}'
haven't tested it myself tho.

slayer_1994 03-29-2017 05:03 AM

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.

TenTenths 03-29-2017 05:05 AM

Quote:

Originally Posted by slayer_1994 (Post 5689670)
@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. :)


All times are GMT -5. The time now is 07:17 AM.