-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pgtype.JSON ERROR: invalid input syntax for type json
with PreferSimpleProtocol = true
#45
Comments
This is an edge case with the simple protocol and One problem is that when using the simple protocol is the destination PostgreSQL type is unknown. The type has to be determined by completely by the Go side. What is a The https://github.com/jackc/pgx/blob/eeda0368e66fafed0a3db500108bdb87b657a88a/values.go#L40 However, when using So I'm not sure if this exact case can be solved without breaking something else. But you can use |
@jackc do you know if this issue is impacted / resolved with the removal of the JSONB type? https://github.com/jackc/pgx/blob/master/CHANGELOG.md#other-changes |
@aethanol It's still an issue with v5. Same fundamental problem though the internal implementation details differ.
|
Thanks for the explanation @jackc. I solved my issue by doing something like this: -- schema.sql
CREATE TABLE IF NOT EXISTS my_table(
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
my_data jsonb
);
-- query.sql
-- name: InsertMyTable :exec
INSERT INTO my_table (data)
VALUES ((@my_data::text)::jsonb); Please let me know if I missed something. |
Error message
Description
When use pgx/v4/stdlib and sqlx to store pgtype.JSON to database, will get an error like above(SQLSTATE 22P02).
I also tried database/sql and got the same errors.
However, with
pgx.ConnectConfig(ctx, connConfig)
, pgtype.JSON worked but []byte not.Code to reproduce
The text was updated successfully, but these errors were encountered: