encoding custom types as jsonb no longe works with v5.6 and above
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
Hi @jackc , we use call `RegisterDefaultPgType` for custom structs like this
```
RegisterDefaultPgType(SomeStruct, "jsonb")
```
and everything would work in v5.5.4.
Now with v5.7 (and I guess with v5.6 too), we get the following errors on insert:
```
failed to create outpost: error writing to DB: ERROR: invalid input syntax for type json
```
not sure if this is the root cause, but I tried to debug it to understand a bit better what's going on and I think [this](https://github.com/jackc/pgx/commit/c1075bfff0752a01d946f40a15e0893f6637c579#commitcomment-146911026:) is the reason it chooses the json codec instead of the jsonb codec.
With v5.7.1 is there a new way to define custom types? btw we use QueryExecModeExec.
Contributor guide
Research direction
Reproduce the insert using RegisterDefaultPgType(SomeStruct, "jsonb") and QueryExecModeExec, comparing v5.5.4 with v5.7.1. Trace why the json codec is selected instead of the jsonb codec and identify the relevant encoding path. Done means custom structs insert successfully as jsonb on the affected versions, with regression coverage added where appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100