【发布时间】:2020-11-09 06:48:18
【问题描述】:
我正在尝试在 shell 脚本中查询跨多个 PostgreSQL 表的记录总数。
shell脚本将由构建管道执行,管道需要知道总行数。
shell 脚本
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
我已经测试了我的查询,它很好,但是从 psql 命令读取 sql 文件有困难,我不确定如何将记录数保存在要由管道读取的变量中。
【问题讨论】:
标签: postgresql shell psql