I'm trying to query the total number of records across multiple PostgreSQL tables in a shell script.
The shell script is to be executed by a build pipeline and the pipeline needs to know the number of total number of rows.
shell script
docker run -it postgres psql "host=xxx.com port=5432 dbname=xxx user=xxx password=xxxw" -f row_count.sql
row_count.sql
select SUM(row_count)
from (
SELECT count(*) as row_count
FROM "table_a"
union all
SELECT count(*) as row_count
FROM "table_b"
union all
SELECT count(*) as row_count
FROM "table_c"
) as total
I have tested my query and it's fine, but having difficulty reading the sql file from the psql
command and I'm not sure how to save the number of records in a variable to be read by the pipeline.