Append appends a Datum to the array, whose parameterized type must be consistent with the type of the Datum.
(v Datum)
| 3486 | // Append appends a Datum to the array, whose parameterized type must be |
| 3487 | // consistent with the type of the Datum. |
| 3488 | func (d *DArray) Append(v Datum) error { |
| 3489 | if v != DNull && !d.ParamTyp.Equivalent(v.ResolvedType()) { |
| 3490 | return errors.AssertionFailedf("cannot append %s to array containing %s", d.ParamTyp, |
| 3491 | v.ResolvedType()) |
| 3492 | } |
| 3493 | if d.Len() >= maxArrayLength { |
| 3494 | return errors.WithStack(errArrayTooLongError) |
| 3495 | } |
| 3496 | if d.ParamTyp.Family() == types.ArrayFamily { |
| 3497 | if v == DNull { |
| 3498 | return errNonHomogeneousArray |
| 3499 | } |
| 3500 | if d.Len() > 0 { |
| 3501 | prevItem := d.Array[d.Len()-1] |
| 3502 | if prevItem == DNull { |
| 3503 | return errNonHomogeneousArray |
| 3504 | } |
| 3505 | expectedLen := MustBeDArray(prevItem).Len() |
| 3506 | if MustBeDArray(v).Len() != expectedLen { |
| 3507 | return errNonHomogeneousArray |
| 3508 | } |
| 3509 | } |
| 3510 | } |
| 3511 | if v == DNull { |
| 3512 | d.HasNulls = true |
| 3513 | } else { |
| 3514 | d.HasNonNulls = true |
| 3515 | } |
| 3516 | d.Array = append(d.Array, v) |
| 3517 | return d.Validate() |
| 3518 | } |
| 3519 | |
| 3520 | // DOid is the Postgres OID datum. It can represent either an OID type or any |
| 3521 | // of the reg* types, such as regproc or regclass. |
no test coverage detected