Controlling psql output

Started by Gauthier, Davealmost 17 years ago6 messagesgeneral
Jump to latest
#1Gauthier, Dave
dave.gauthier@intel.com

Hi:

Using a single psql command to generate stdout in linux that will be redirected to a file. Many rows with 1 column are returned. I want no header, no footer, no blank lines at the top or bottom, no initial space before each record. This is what I'm trying...

psql -P tuples_only=on,footer=off,border=0 mydb

This gets rid of the header and footer OK. But there is still a blank line as the first line in stdout. Also, each record has a preceding space before the column value.

Is there a way to do what I want?

-dave

#2Joshua D. Drake
jd@commandprompt.com
In reply to: Gauthier, Dave (#1)
Re: Controlling psql output

On Fri, 2009-05-08 at 09:51 -0700, Gauthier, Dave wrote:

Hi:

Using a single psql command to generate stdout in linux that will be
redirected to a file. Many rows with 1 column are returned. I want
no header, no footer, no blank lines at the top or bottom, no initial
space before each record. This is what I’m trying...

psql –P tuples_only=on,footer=off,border=0 mydb

psql -A -t

jd@jd-laptop:~$ psql -A -t -U postgres -c "select * from bool_test"
f
jd@jd-laptop:~$

Sincerely,

Joshua D. Drake

--
PostgreSQL - XMPP: jdrake@jabber.postgresql.org
Consulting, Development, Support, Training
503-667-4564 - http://www.commandprompt.com/
The PostgreSQL Company, serving since 1997

#3Christophe Pettus
xof@thebuild.com
In reply to: Gauthier, Dave (#1)
Re: Controlling psql output

On May 8, 2009, at 9:51 AM, Gauthier, Dave wrote:

This gets rid of the header and footer OK. But there is still a
blank line as the first line in stdout. Also, each record has a
preceding space before the column value.

Is there a way to do what I want?

sed?

#4Ben
bench@silentmedia.com
In reply to: Gauthier, Dave (#1)
Re: Controlling psql output

On Fri, 8 May 2009, Gauthier, Dave wrote:

Hi:

Using a single psql command to generate stdout in linux that will be redirected to a file. Many rows with 1 column are returned. I want no header, no footer, no blank lines at the top or bottom, no initial space before each record. This is what I'm trying...

psql -P tuples_only=on,footer=off,border=0 mydb

This gets rid of the header and footer OK. But there is still a blank line as the first line in stdout. Also, each record has a preceding space before the column value.

Is there a way to do what I want?

Do you need to have the rows aligned? The -A flag may work for you, though
you might want to specify a different column seperator.

#5Gauthier, Dave
dave.gauthier@intel.com
In reply to: Ben (#4)
Re: Controlling psql output

-A -t worked great. Thanks !
-dave

-----Original Message-----
From: Ben Chobot [mailto:bench@silentmedia.com]
Sent: Friday, May 08, 2009 2:03 PM
To: Gauthier, Dave
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Controlling psql output

On Fri, 8 May 2009, Gauthier, Dave wrote:

Hi:

Using a single psql command to generate stdout in linux that will be redirected to a file. Many rows with 1 column are returned. I want no header, no footer, no blank lines at the top or bottom, no initial space before each record. This is what I'm trying...

psql -P tuples_only=on,footer=off,border=0 mydb

This gets rid of the header and footer OK. But there is still a blank line as the first line in stdout. Also, each record has a preceding space before the column value.

Is there a way to do what I want?

Do you need to have the rows aligned? The -A flag may work for you, though
you might want to specify a different column seperator.

#6Jasen Betts
jasen@xnet.co.nz
In reply to: Gauthier, Dave (#1)
Re: Controlling psql output

On 2009-05-08, Gauthier, Dave <dave.gauthier@intel.com> wrote:

--_000_482E80323A35A54498B8B70FF2B87980040106E94Bazsmsx504amrc_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi:

Using a single psql command to generate stdout in linux that will be redire=
cted to a file. Many rows with 1 column are returned. I want no header, n=
o footer, no blank lines at the top or bottom, no initial space before each=
record. This is what I'm trying...

psql -P tuples_only=3Don,footer=3Doff,border=3D0 mydb

This gets rid of the header and footer OK. But there is still a blank line=
as the first line in stdout. Also, each record has a preceding space befo=
re the column value.

Is there a way to do what I want?

use "copy (select ...) to stdout" instead of "select ..."

requires 8.3 or greater.
as a bonus nulls and control characters re represented unambiguously.