I have a sample table with this structure in Redshift:
{
ID Integer (pk)
Description Varchar NULL
}
I use Redshift Data Service to query it (api reference here). The results are of type GetStatementResultOutput which
contains a property Records of type [][]type.Field.
Now, this type.Field is just an interface to group all the possible field types:
// A data value in a column.
//
// The following types satisfy this interface:
// FieldMemberBlobValue
// FieldMemberBooleanValue
// FieldMemberDoubleValue
// FieldMemberIsNull
// FieldMemberLongValue
// FieldMemberStringValue
type Field interface {
isField()
}
Each of those types really have a Value property that returns the value of the cell. The problem is I don't really have access to the underlying types and I have to extract the values somehow. I'm pretty new at golang and figured a way to extract the values:
type ValueExtractor struct {
Value interface{}
}
columnValueBytes, err := json.Marshal(columnValue)
if err != nil {
logger.Err(err)
}
var valueEx ValueExtractor
err = json.Unmarshal(columnValueBytes, &valueEx)
// The value is here: valueEx.Value
but when the value is null a field of this type is used:
// A value that indicates whether the data is NULL.
type FieldMemberIsNull struct {
Value bool
noSmithyDocumentSerde
}
func (*FieldMemberIsNull) isField() {}
So my value extractor gets true instead of NULL.
What would be the appropriate way of achieving what I want?
Thank you!