0

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?

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
Corvax
  • 684
  • 7
  • 9
  • 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

1

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
  • 539,169
  • 125
  • 977
  • 1,137