Any reason to use sql.NullString rather than *string?
5,200 views
Skip to first unread message
Hǎiliàng
unread,
Feb 26, 2013, 9:26:48 AM2/26/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
Doc says that Null* types in database/sql are introduced to support nullable value, but I have also tried to use *string, *int and *time.Time and it turns out that they can also be stored and retrieved from database and represents null.
Is there any reason to use these sql.Null* types rather than pointers to primitive types?
Hǎiliàng
Julien Schmidt
unread,
Feb 26, 2013, 11:14:21 AM2/26/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
How else should you return the nil value? Set the pointer address to nil?
Russ Cox
unread,
Feb 26, 2013, 12:19:51 PM2/26/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Hǎiliàng, golang-nuts
There's no effective difference. We thought people might want to use NullString because it is so common and perhaps expresses the intent more clearly than *string. But either will work.