Difference between *string and sql.NullString

SQL has different null values than Golang.

If you look at the definition of sql.NullString then this is what you get:

type NullString struct {
    String string
    Valid  bool // Valid is true if String is not NULL
}

As you can see, sql.NullString is a way to represent null string coming from SQL (which correspond to “NULL”).
On the other hand, a nil *string is a pointer to a string which is nil, so the two are different.

Leave a Comment