Open EfraimDim opened 8 months ago
The problem is unmarshalling the literal JSON string "foo"
into a Go string removes the quotation marks. This is correct behavior.
When encoding a string to a PostgreSQL json
type, pgx assumes that it is an encoded JSON document, not a literal string that should be encoded into a JSON value. This is also correct behavior. Or at least the behavior that we would almost always want when using a string as a query parameter.
Unfortunately, these two (correct) behaviors are incompatible.
I don't think there is a general solution that would allow using a pgx.Rows
that has JSON documents that consist entirely of a JSON string value as a pgx.CopyFromSource
. It might be possible to do a special case, but actually the entire approach of using pgx.Rows
as a pgx.CopyFromSource
is sub-optimal.
Instead you can directly wire CopyTo
and CopyFrom
together. See https://github.com/jackc/pgx/issues/867.
Hello, I am trying to using CopyFrom with pgx5 connection to copy from a table with a JSON field but the json is inserted in the original insert query as '"json_string"'. When using CopyFrom with rows pgx5.Rows and a JSON value of this string, it throws an error: ERROR: invalid input syntax for type json (SQLSTATE 22P02)
Steps to reproduce the behavior:
Version
**Edited code: 1/03/24