Skip to content

Conversation

@epelc
Copy link
Contributor

@epelc epelc commented Mar 15, 2019

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
Copy link

dynajoe commented May 7, 2020

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
@arp242 arp242 force-pushed the fix/nil-byte-interface branch from 93193f0 to 22781f8 Compare January 3, 2026 14:36
@arp242 arp242 merged commit fb12405 into lib:master Jan 3, 2026
13 checks passed
@arp242 arp242 added the bug label Jan 3, 2026
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