Re: how to concat/concat_ws all fields without braces

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Jean Louis <bugs(at)gnu(dot)support>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: how to concat/concat_ws all fields without braces
Date: 2019-06-15 09:36:21
Message-ID: CAFj8pRAKcK96oXzTtR3+wWWi-FD2Tfr0bm89GsVWG9FzrNkA9g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

so 15. 6. 2019 v 8:20 odesílatel Jean Louis <bugs(at)gnu(dot)support> napsal:

> Hello,
>
> I have tried doing something like:
>
> SELECT concat_ws(' ', table.*) FROM table;
>
> and if I do that way, it is essentially same as
>
> SELECT concat(table.*) FROM table;
>
> and I get the items in braces like (1,something).
>
> Why do I get it in braces?
>
> Is there a way without specifying specific fields
> to get all items concatenated without braces?
>
> I would prefer conat_ws option.
>

It cannot to work. Postgres try to convert composite type based on all
fields to one text value, and this value is passed as one argument. It can
work because concat, concat_ws has 'variadic "any" parameter. But it does
cannot to work like you expect.

you can write own function that will do what you want

create or replace function rec_concat_fields(record, text)
returns text as $$
begin
return string_agg(value, '|') from json_each_text(row_to_json($1));
end
$$ language plpgsql;

postgres=# select rec_concat_fields(foo.*, '*') from foo;
┌───────────────────┐
│ rec_concat_fields │
╞═══════════════════╡
│ ahoj|svete │
└───────────────────┘
(1 row)

Regards

Pavel

> Jean
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2019-06-15 09:36:26 Re: how to concat/concat_ws all fields without braces
Previous Message Tiemen Ruiten 2019-06-15 08:49:38 Re: checkpoints taking much longer than expected