3

I use a file where I have all my SQL queries. I run the following command:

psql -U postgres -d rails_development -a -f ProjectApp/db/Query.sql

Output is as following:

SELECT * FROM "Users"
id | username | firstname | lastname | [...]
...
(27 rows)

I would like to remove query message (SELECT * FROM "Users") from output. Is that possible?

Rares Mardare
  • 193
  • 1
  • 4
  • 13

2 Answers2

5

-a or --echo-all echoes all input from script. You won't need that. Include --tuples-only or the -t flag to print rows only like so:

psql -U postgres -d rails_development --tuples-only -f ProjectApp/db/Query.sql

psql --help says:

...
Input and output options:
  -a, --echo-all           echo all input from script
  -e, --echo-queries       echo commands sent to server
  ...

Output format options:
  ...
  -R, --record-separator=STRING
                           set record separator (default: newline)
  -t, --tuples-only        print rows only
  ...
zedfoxus
  • 35,121
  • 5
  • 64
  • 63
1

The -a option repeats every query on the terminal (STDOUT), you want to remove this option from your commandline.

A. Scherbaum
  • 809
  • 4
  • 8