PostgreSQL:Select 没有页眉/页脚行的语句

PostgreSQL: Select statement without header / footer lines

select distinct table_schema from information_schema.tables;

提供类似

的内容
   table_schema    
--------------------
 mySchema
 pg_catalog
 information_schema
 anotherSchem
(4 rows)

如何修改命令,以免看到前两行(table_schema 和---)和最后一行(...行)?

我在 bash 脚本中使用 psql 命令。如何在此处添加 \pset tuples ...

psql 中,您可以使用 meta command \pset tuples_only 来关闭它:

postgres=> select distinct table_schema from information_schema.tables;
    table_schema
--------------------
 public
 pg_catalog
 information_schema
(3 rows)

postgres=>postgres=> \pset tuples_only
Tuples only is on.

postgres=> select distinct table_schema from information_schema.tables;
 public
 pg_catalog
 information_schema

您可以在启动 psql 时使用命令行参数 --tuples-only:

启用此功能
psql --tuples-only -U micha -d some_db

从 shell 脚本中,您可以使用 psql 选项 --tuples-only(更短的 -t),这比使用 \pset 更方便:

psql -t -c 'SELECT ...'

如果您只对单个查询结果感兴趣,通常最好同时取消对齐和状态消息:

result="$(psql -Atq -c 'SELECT ...')"