You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to use pgtype.JSONB.Set to assign interface{} data that is JSON-like (such as a map or a struct) but does not conform to JSONB’s expected format, Set completes successfully, implying compatibility. However, checking with reflect.DeepEqual reveals that the data has not been assigned correctly. The expected behavior would be for Set to return an error when encountering incompatible data structures, as this would make troubleshooting simpler and avoid silent errors in JSONB assignments.
Sample snippet
funcCreatePageContent(ctx context.Context, conn*pgx.Conn, pageIDint64, datainterface{}) (PageContent, error) {
QTAG:="Q_CREATE_PAGE_CONTENT"// Initialize JSONB objectdetails:=&pgtype.JSONB{}
// Attempt to set data in JSONBiferr:=details.Set(data); err!=nil {
returnPageContent{}, errors.Wrapf(err, "query error (qtag=%s)", QTAG)
}
// Use DeepEqual to verifyif!reflect.DeepEqual(details, data) {
// Expecting Set to fail, but it does notfmt.Printf("Set succeeded, but data was not equivalent. details: %v, data: %v\n", details, data)
}
returnPageContent{}, nil
}
data is like {"data":"some complex string read from files, could have new line\n, tabs \t or white space character or any indefinite character, whatever possible case."}
The text was updated successfully, but these errors were encountered:
When attempting to use
pgtype.JSONB.Set
to assigninterface{}
data that is JSON-like (such as a map or a struct) but does not conform to JSONB’s expected format,Set
completes successfully, implying compatibility. However, checking withreflect.DeepEqual
reveals that the data has not been assigned correctly. The expected behavior would be forSet
to return an error when encountering incompatible data structures, as this would make troubleshooting simpler and avoid silent errors in JSONB assignments.Sample snippet
data is like
{"data":"some complex string read from files, could have new line\n, tabs \t or white space character or any indefinite character, whatever possible case."}
The text was updated successfully, but these errors were encountered: