< Prev: TIMESTAMPTZ/DATETIME
Up: Column Types
Next: JSON >

Column Types: ARRAY

The sq representation of ARRAY types is the ArrayField. You can convert slices into an ArrayField, but only for certain types. The slice/array types you can convert between are show below:
func Array(slice interface{}) ArrayField

// When converting a slice to an ArrayField
Array(mySlice)
// When scanning an ArrayField back to a slice with [Struct Mapping](/sq/basics/struct-mapping.html#select-one-vs-many)
row.ScanArray(&mySlice, tbl.SOME_ARRAY_COLUMN)
// supported conversions:
// []bool     <=> BOOL[]
// []float64  <=> FLOAT[]
// []int       => INT[]
// []int64    <=  INT[]
// []int64    <=> BIGINT[]
// []string   <=> TEXT[]

Take note that if you want to map an INT[]/BIGINT[] Array back to a Go slice, you have to use []int64 and not []int.

Here are the available Predicate operations on an ArrayField:
func (f ArrayField) IsNull() Predicate          // f IS NULL
func (f ArrayField) IsNotNull() Predicate       // f IS NOT NULL
func (f ArrayField) In(v interface{}) Predicate // f IN (v)

// ArrayField
func (f ArrayField) Eq(field ArrayField) Predicate          // f = field
func (f ArrayField) Ne(field ArrayField) Predicate          // f <> field
func (f ArrayField) Gt(field ArrayField) Predicate          // f > field
func (f ArrayField) Ge(field ArrayField) Predicate          // f >= field
func (f ArrayField) Lt(field ArrayField) Predicate          // f < field
func (f ArrayField) Le(field ArrayField) Predicate          // f <= field
func (f ArrayField) Contains(field ArrayField) Predicate    // f @> field
func (f ArrayField) ContainedBy(field ArrayField) Predicate // f <@ field
func (f ArrayField) Overlaps(field ArrayField) Predicate    // f && field
< Prev: TIMESTAMPTZ/DATETIME
Up: Column Types
Next: JSON >