Re: Escape Python to `json[]` for `COPY FROM` PostgreSQL insertion? - Mailing list psycopg

From Daniele Varrazzo
Subject Re: Escape Python to `json[]` for `COPY FROM` PostgreSQL insertion?
Date
Msg-id CA+mi_8YZt4QjUY5YMTUVZGByRZ88f=X=TEoLuJG6ZQy3SiuW8w@mail.gmail.com
Whole thread Raw
In response to Escape Python to `json[]` for `COPY FROM` PostgreSQL insertion?  (Samuel Marks <samuelmarks@gmail.com>)
List psycopg
On Tue, 21 Feb 2023 at 05:34, Samuel Marks <samuelmarks@gmail.com> wrote:
>
> How do I insert into a table with a `json[]` column using the `COPY FROM` syntax?

you can just use psycopg 3 and pass it the records as tuples with the
objects you want to copy. The values of your json[] fields can be a
list of `Json` wrappers.

https://www.psycopg.org/psycopg3/docs/basic/copy.html#writing-data-row-by-row
https://www.psycopg.org/psycopg3/docs/basic/adapt.html#json-adaptation

If you want to know the escaping rules, they are in the Postgres documentation:

https://www.postgresql.org/docs/current/arrays.html#ARRAYS-INPUT

-- Daniele



psycopg by date:

Previous
From: Aryeh Leib Taurog
Date:
Subject: Re: Escape Python to `json[]` for `COPY FROM` PostgreSQL insertion?
Next
From: "Michael P. McDonnell"
Date:
Subject: Consecutive Inserts Freeze Execution of Psycopg3