Re: Emitting JSON to file using COPY TO

From: Davin Shearer <davin(at)apache(dot)org>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Emitting JSON to file using COPY TO
Date: 2023-11-29 15:32:54
Message-ID: CALvfUkCq3pvkmniWEKZwkbA6hNNvkANF3OamMfhC170RgY+HJg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Thanks for the responses everyone.

I worked around the issue using the `psql -tc` method as Filip described.

I think it would be great to support writing JSON using COPY TO at
some point so I can emit JSON to files using a PostgreSQL function directly.

-Davin

On Tue, Nov 28, 2023 at 2:36 AM Filip Sedlák <filip(at)sedlakovi(dot)org> wrote:

> This would be a very special case for COPY. It applies only to a single
> column of JSON values. The original problem can be solved with psql
> --tuples-only as David wrote earlier.
>
>
> $ psql -tc 'select json_agg(row_to_json(t))
> from (select * from public.tbl_json_test) t;'
>
> [{"id":1,"t_test":"here's a \"string\""}]
>
>
> Special-casing any encoding/escaping scheme leads to bugs and harder
> parsing.
>
> Just my 2c.
>
> --
> Filip Sedlák
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sri Mrudula Attili 2023-11-29 17:20:20 Re: Could not read from file "pg_subtrans/00F5" at offset 122880: Success.
Previous Message Chris Travers 2023-11-29 11:37:00 Re: Fixing or Mitigating this ERROR: invalid page in block 35217 of relation base/16421/3192429

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2023-11-29 15:50:42 Re: proposal: possibility to read dumped table's name from file
Previous Message Daniel Gustafsson 2023-11-29 15:26:16 Re: SSL tests fail on OpenSSL v3.2.0