Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: Select statement without header / footer lines

select distinct table_schema from information_schema.tables;

provides something like

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

How to modify the command, in order not to see the first two (table_schema and ---) nor the last line (... rows)?

I'm using a psql command in a bash script. how can I add \pset tuples ... there?

like image 514
StOMicha Avatar asked Jul 16 '26 01:07

StOMicha


1 Answers

From a shell script, you can use the psql option --tuples-only (shorter -t), which is more convenient than using \pset:

psql -t -c 'SELECT ...'

If you are only interested in a single query result, it is often best to do away with alignment and status messages as well:

result="$(psql -Atq -c 'SELECT ...')"
like image 97
Laurenz Albe Avatar answered Jul 22 '26 06:07

Laurenz Albe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!