close
Skip to content

fix(conn): properly inspect interfaces for nil values#838

Merged
arp242 merged 2 commits into
lib:masterfrom
epelc:fix/nil-byte-interface
Jan 3, 2026
Merged

fix(conn): properly inspect interfaces for nil values#838
arp242 merged 2 commits into
lib:masterfrom
epelc:fix/nil-byte-interface

Conversation

@epelc

@epelc epelc commented Mar 15, 2019

Copy link
Copy Markdown
Contributor

Fixes #773 by further inspecting arguments to check if they are nil interfaces or slices.

Sending a nil byte slice use to not work because it was a nil value of type []byte which != nil hence it would really send an empty byte slice. This prevented you from setting columns to null unless you had a different path to send an explicit nil which also had no type(confusing and a pain to implement). Checking interface values equal nil is a common bug in go which usually requires using the reflect package to further inspect the interface's actual value is nil since the typing usually isn't.

This does slightly slow down writes theoretically but it should be worth it for such a common use case and standard feature of sending nil.

Fixes #773

@dynajoe

dynajoe commented May 7, 2020

Copy link
Copy Markdown

I have a similar issue. What's the best way to go since this PR has been open over a year?

@arp242 arp242 added the needs-test Needs a test before it can be merged label Dec 31, 2025
@arp242
arp242 force-pushed the fix/nil-byte-interface branch from aa6d63d to d9270f9 Compare January 3, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug needs-test Needs a test before it can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inserting []byte(nil) to bytea is not treated as NULL

3 participants