首页 > 解决方案 > PostgreSQL:选择没有页眉/页脚行的语句

问题描述

select distinct table_schema from information_schema.tables;

提供类似的东西

   table_schema    
--------------------
 mySchema
 pg_catalog
 information_schema
 anotherSchem
(4 rows)

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

我在 bash 脚本中使用 psql 命令。我怎样才能在\pset tuples ...那里添加?

标签: postgresqlpsql

解决方案


psql您可以使用meta命令 \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

推荐阅读