HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlCritical

How to turn off header only in psql (postgresql)

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
turnpostgresqlheaderpsqlhowonlyoff

Problem

I'm using PostgreSQL 9.1.X

I am trying to build psql script to print results without a header but including a footer.

http://www.postgresql.org/docs/9.1/static/app-psql.html

From the document above

\pset tuples_only


will turn both header and footer off. and

\pset footer off


will turn footer off only.

Is there a way in psql to turn the header off and keep the footer on?

I know there are many ways to work around this issue using shell/perl/whatever text tool you like, however I am wondering why there is a config for the footer but not one for the header?

id <--this line I don't want
---- <-- this line I don't want either
 1  <-- this line, yes
(1 row) <-- yes, I want it!

Solution

When executing psql from shell you can use -t (prints tuples only) option:

$ psql -t -c "SELECT version();"
 PostgreSQL 9.5.5 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit


Within psql use \t to turn off printing header and row count.

Code Snippets

$ psql -t -c "SELECT version();"
 PostgreSQL 9.5.5 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit

Context

StackExchange Database Administrators Q#24215, answer score: 56

Revisions (0)

No revisions yet.