fix: gracefully handle empty hstore in pgdialect #1010
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the current implementation of
hstore
ingit.luolix.top/uptrace/bun/dialect/pgdialect
, an emptyhstore
is encoded properly in the database as''
but can not be retrieved.It is handled properly for a
var md map[string]string = nil
whenNULL
is inserted in database and an empty map is returned when querying back the record, but when using amap[string]string{}
it will insert''
(which is expected) but will fail with the following error:This PR make sure an empty
hstore
is handled gracefully in thehstoreParser
as well as adds test cases for this issues inpgdialect
itself (for the parser AND the appender) as well as in theinternal/dbtest
package.This fix is relatively crucial to us, as we tend to store user defined metadata in
hstore
and it may happen that a user removes all key value pairs from there. Currently, we have to check if the changes made to a metadata field makes it empty and force the field to be null, being able to handle empty hstore gracefully at the database driver level would make our life quite easier here as it seems like a legitimate use of that type.