Re: how to concat/concat_ws all fields without braces - Mailing list pgsql-general

From Jean Louis
Subject Re: how to concat/concat_ws all fields without braces
Date
Msg-id 20190615142038.GJ10179@protected.rcdrun.com
Whole thread Raw
In response to Re: how to concat/concat_ws all fields without braces  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: how to concat/concat_ws all fields without braces
List pgsql-general
Dear Pavel,

Ahoj.

* Pavel Stehule <pavel.stehule@gmail.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

Jean



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Copy Bulk Ignore Duplicated
Next
From: Jean Louis
Date:
Subject: Re: how to concat/concat_ws all fields without braces