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 14:37:19
Message-ID: CAFj8pRAgaZqqQN-GD3a4RtWqgLOt_D84w5fE27dmZn7n=vNBoA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

> Dear Pavel,
>
> Ahoj.
>
> * Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> [2019-06-15 11:37]:
> > 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)
> >
>
> I have tried that one, not working quite;
>
> create or replace function concat_fields(record, text)
> returns text as $$
> begin
> return string_agg(value, ' ') from json_each_text(row_to_json($1));
> end
> $$ language plpgsql;
> rcdbusiness$# ERROR: PL/pgSQL functions cannot accept type record
>

depends on Postgres version. I have 12, but probably it should to work with
Postgres 10, 11

Pavel

> Jean
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Noah Misch 2019-06-15 18:37:59 Re: pg_upgrade can result in early wraparound on databases with high transaction load
Previous Message Jean Louis 2019-06-15 14:22:00 Re: how to concat/concat_ws all fields without braces