diff --git a/aclitem_array.go b/aclitem_array.go index fe0af434..0a829295 100644 --- a/aclitem_array.go +++ b/aclitem_array.go @@ -13,6 +13,12 @@ type ACLItemArray struct { } func (dst *ACLItemArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = ACLItemArray{Status: Null} + return nil + } + switch value := src.(type) { case []string: @@ -38,7 +44,7 @@ func (dst *ACLItemArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to ACLItem", value) + return errors.Errorf("cannot convert %v to ACLItemArray", value) } return nil diff --git a/bool_array.go b/bool_array.go index e23c27e5..67dd92a7 100644 --- a/bool_array.go +++ b/bool_array.go @@ -15,6 +15,12 @@ type BoolArray struct { } func (dst *BoolArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = BoolArray{Status: Null} + return nil + } + switch value := src.(type) { case []bool: @@ -40,7 +46,7 @@ func (dst *BoolArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Bool", value) + return errors.Errorf("cannot convert %v to BoolArray", value) } return nil diff --git a/bytea_array.go b/bytea_array.go index f2842179..c8eb5669 100644 --- a/bytea_array.go +++ b/bytea_array.go @@ -15,6 +15,12 @@ type ByteaArray struct { } func (dst *ByteaArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = ByteaArray{Status: Null} + return nil + } + switch value := src.(type) { case [][]byte: @@ -40,7 +46,7 @@ func (dst *ByteaArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Bytea", value) + return errors.Errorf("cannot convert %v to ByteaArray", value) } return nil diff --git a/cidr_array.go b/cidr_array.go index 2373da46..e4bb7614 100644 --- a/cidr_array.go +++ b/cidr_array.go @@ -16,6 +16,12 @@ type CIDRArray struct { } func (dst *CIDRArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = CIDRArray{Status: Null} + return nil + } + switch value := src.(type) { case []*net.IPNet: @@ -60,7 +66,7 @@ func (dst *CIDRArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to CIDR", value) + return errors.Errorf("cannot convert %v to CIDRArray", value) } return nil diff --git a/date_array.go b/date_array.go index 383945e7..0cb64581 100644 --- a/date_array.go +++ b/date_array.go @@ -16,6 +16,12 @@ type DateArray struct { } func (dst *DateArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = DateArray{Status: Null} + return nil + } + switch value := src.(type) { case []time.Time: @@ -41,7 +47,7 @@ func (dst *DateArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Date", value) + return errors.Errorf("cannot convert %v to DateArray", value) } return nil diff --git a/float4_array.go b/float4_array.go index 6499064b..02c28caa 100644 --- a/float4_array.go +++ b/float4_array.go @@ -15,6 +15,12 @@ type Float4Array struct { } func (dst *Float4Array) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = Float4Array{Status: Null} + return nil + } + switch value := src.(type) { case []float32: @@ -40,7 +46,7 @@ func (dst *Float4Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Float4", value) + return errors.Errorf("cannot convert %v to Float4Array", value) } return nil diff --git a/float8_array.go b/float8_array.go index 27b24836..b92a8205 100644 --- a/float8_array.go +++ b/float8_array.go @@ -15,6 +15,12 @@ type Float8Array struct { } func (dst *Float8Array) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = Float8Array{Status: Null} + return nil + } + switch value := src.(type) { case []float64: @@ -40,7 +46,7 @@ func (dst *Float8Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Float8", value) + return errors.Errorf("cannot convert %v to Float8Array", value) } return nil diff --git a/hstore_array.go b/hstore_array.go index 38ce457b..80530c26 100644 --- a/hstore_array.go +++ b/hstore_array.go @@ -15,6 +15,12 @@ type HstoreArray struct { } func (dst *HstoreArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = HstoreArray{Status: Null} + return nil + } + switch value := src.(type) { case []map[string]string: @@ -40,7 +46,7 @@ func (dst *HstoreArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Hstore", value) + return errors.Errorf("cannot convert %v to HstoreArray", value) } return nil diff --git a/inet_array.go b/inet_array.go index 3ece23eb..f3e4efbf 100644 --- a/inet_array.go +++ b/inet_array.go @@ -16,6 +16,12 @@ type InetArray struct { } func (dst *InetArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = InetArray{Status: Null} + return nil + } + switch value := src.(type) { case []*net.IPNet: @@ -60,7 +66,7 @@ func (dst *InetArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Inet", value) + return errors.Errorf("cannot convert %v to InetArray", value) } return nil diff --git a/int2_array.go b/int2_array.go index e939411b..f50d9275 100644 --- a/int2_array.go +++ b/int2_array.go @@ -15,6 +15,12 @@ type Int2Array struct { } func (dst *Int2Array) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = Int2Array{Status: Null} + return nil + } + switch value := src.(type) { case []int16: @@ -59,7 +65,7 @@ func (dst *Int2Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int2", value) + return errors.Errorf("cannot convert %v to Int2Array", value) } return nil diff --git a/int4_array.go b/int4_array.go index 1a907d2e..6c9418ba 100644 --- a/int4_array.go +++ b/int4_array.go @@ -15,6 +15,12 @@ type Int4Array struct { } func (dst *Int4Array) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = Int4Array{Status: Null} + return nil + } + switch value := src.(type) { case []int32: @@ -59,7 +65,7 @@ func (dst *Int4Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int4", value) + return errors.Errorf("cannot convert %v to Int4Array", value) } return nil diff --git a/int8_array.go b/int8_array.go index 4f3ab4dc..bb6ce004 100644 --- a/int8_array.go +++ b/int8_array.go @@ -15,6 +15,12 @@ type Int8Array struct { } func (dst *Int8Array) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = Int8Array{Status: Null} + return nil + } + switch value := src.(type) { case []int64: @@ -59,7 +65,7 @@ func (dst *Int8Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int8", value) + return errors.Errorf("cannot convert %v to Int8Array", value) } return nil diff --git a/numeric_array.go b/numeric_array.go index 6dfbe5e3..d991234a 100644 --- a/numeric_array.go +++ b/numeric_array.go @@ -15,6 +15,12 @@ type NumericArray struct { } func (dst *NumericArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = NumericArray{Status: Null} + return nil + } + switch value := src.(type) { case []float32: @@ -59,7 +65,7 @@ func (dst *NumericArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Numeric", value) + return errors.Errorf("cannot convert %v to NumericArray", value) } return nil diff --git a/text_array.go b/text_array.go index 2609a2cc..e40f4b86 100644 --- a/text_array.go +++ b/text_array.go @@ -15,6 +15,12 @@ type TextArray struct { } func (dst *TextArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = TextArray{Status: Null} + return nil + } + switch value := src.(type) { case []string: @@ -40,7 +46,7 @@ func (dst *TextArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Text", value) + return errors.Errorf("cannot convert %v to TextArray", value) } return nil diff --git a/timestamp_array.go b/timestamp_array.go index be281f2e..546a3810 100644 --- a/timestamp_array.go +++ b/timestamp_array.go @@ -16,6 +16,12 @@ type TimestampArray struct { } func (dst *TimestampArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = TimestampArray{Status: Null} + return nil + } + switch value := src.(type) { case []time.Time: @@ -41,7 +47,7 @@ func (dst *TimestampArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Timestamp", value) + return errors.Errorf("cannot convert %v to TimestampArray", value) } return nil diff --git a/timestamptz_array.go b/timestamptz_array.go index 086a4ef0..88b6cc5f 100644 --- a/timestamptz_array.go +++ b/timestamptz_array.go @@ -16,6 +16,12 @@ type TimestamptzArray struct { } func (dst *TimestamptzArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = TimestamptzArray{Status: Null} + return nil + } + switch value := src.(type) { case []time.Time: @@ -41,7 +47,7 @@ func (dst *TimestamptzArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Timestamptz", value) + return errors.Errorf("cannot convert %v to TimestamptzArray", value) } return nil diff --git a/typed_array.go.erb b/typed_array.go.erb index 7a69d0ab..6fafc2df 100644 --- a/typed_array.go.erb +++ b/typed_array.go.erb @@ -15,6 +15,12 @@ type <%= pgtype_array_type %> struct { } func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = <%= pgtype_array_type %>{Status: Null} + return nil + } + switch value := src.(type) { <% go_array_types.split(",").each do |t| %> case <%= t %>: @@ -40,7 +46,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to <%= pgtype_element_type %>", value) + return errors.Errorf("cannot convert %v to <%= pgtype_array_type %>", value) } return nil diff --git a/typed_array_gen.sh b/typed_array_gen.sh index 1aa6c354..80ece93c 100644 --- a/typed_array_gen.sh +++ b/typed_array_gen.sh @@ -15,4 +15,5 @@ erb pgtype_array_type=ByteaArray pgtype_element_type=Bytea go_array_types=[][]by erb pgtype_array_type=ACLItemArray pgtype_element_type=ACLItem go_array_types=[]string element_type_name=aclitem text_null=NULL binary_format=false typed_array.go.erb > aclitem_array.go erb pgtype_array_type=HstoreArray pgtype_element_type=Hstore go_array_types=[]map[string]string element_type_name=hstore text_null=NULL binary_format=true typed_array.go.erb > hstore_array.go erb pgtype_array_type=NumericArray pgtype_element_type=Numeric go_array_types=[]float32,[]float64 element_type_name=numeric text_null=NULL binary_format=true typed_array.go.erb > numeric_array.go +erb pgtype_array_type=UUIDArray pgtype_element_type=UUID go_array_types=[][16]byte,[][]byte,[]string element_type_name=uuid text_null=NULL binary_format=true typed_array.go.erb > uuid_array.go goimports -w *_array.go diff --git a/uuid_array.go b/uuid_array.go index c18aec4f..9c7843a7 100644 --- a/uuid_array.go +++ b/uuid_array.go @@ -15,6 +15,7 @@ type UUIDArray struct { } func (dst *UUIDArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different if src == nil { *dst = UUIDArray{Status: Null} return nil @@ -80,7 +81,7 @@ func (dst *UUIDArray) Set(src interface{}) error { } default: - if originalSrc, ok := underlyingPtrType(src); ok { + if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } return errors.Errorf("cannot convert %v to UUIDArray", value) diff --git a/varchar_array.go b/varchar_array.go index fecbb2e5..09eba3ea 100644 --- a/varchar_array.go +++ b/varchar_array.go @@ -15,6 +15,12 @@ type VarcharArray struct { } func (dst *VarcharArray) Set(src interface{}) error { + // untyped nil and typed nil interfaces are different + if src == nil { + *dst = VarcharArray{Status: Null} + return nil + } + switch value := src.(type) { case []string: @@ -40,7 +46,7 @@ func (dst *VarcharArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Varchar", value) + return errors.Errorf("cannot convert %v to VarcharArray", value) } return nil