public inbox for [email protected]
help / color / mirror / Atom feedFrom: Daniele Varrazzo <[email protected]>
To: Samuel Marks <[email protected]>
Cc: [email protected]
Subject: Re: Escape Python to `json[]` for `COPY FROM` PostgreSQL insertion?
Date: Tue, 21 Feb 2023 09:57:05 +0000
Message-ID: <CA+mi_8YZt4QjUY5YMTUVZGByRZ88f=X=TEoLuJG6ZQy3SiuW8w@mail.gmail.com> (raw)
In-Reply-To: <CAMfPbcbOoC0k2CoSDo1jR-nh98N5qs_aU1T9hEXYpMfpQb-bZA@mail.gmail.com>
References: <CAMfPbcbOoC0k2CoSDo1jR-nh98N5qs_aU1T9hEXYpMfpQb-bZA@mail.gmail.com>
On Tue, 21 Feb 2023 at 05:34, Samuel Marks <[email protected]> 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
view thread (4+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Escape Python to `json[]` for `COPY FROM` PostgreSQL insertion?
In-Reply-To: <CA+mi_8YZt4QjUY5YMTUVZGByRZ88f=X=TEoLuJG6ZQy3SiuW8w@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox