1

Couldn't find such question answered. I'm selecting one column from the table and I want to have output in one line in psql console to be easily copied.

select id from my_table;

Instead of

  id  
------
 1295
 1359
  568
   36
  395
  569
 1216
 1296

I would like to see

1295 1359 568 36 395 569 1216 1296

Is it possible in psql console?

Corvax
  • 782
  • 8
  • 13
  • Related: [How to concatenate strings of a string field in a PostgreSQL 'group by' query?](https://stackoverflow.com/q/43870/190597) – unutbu Apr 10 '19 at 12:17

1 Answers1

3

Use string_agg():

SELECT string_agg(id::text, ' ') FROM my_table;

The cast to text is probably necessary if id is not a string type.

See:

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228