MakeScalar constructs a new instance of a scalar type (i.e. not array or tuple types) using the provided fields.
(family Family, o oid.Oid, precision, width int32, locale string)
| 640 | // MakeScalar constructs a new instance of a scalar type (i.e. not array or |
| 641 | // tuple types) using the provided fields. |
| 642 | func MakeScalar(family Family, o oid.Oid, precision, width int32, locale string) *T { |
| 643 | t := OidToType[o] |
| 644 | if family != t.Family() { |
| 645 | if family != CollatedStringFamily || StringFamily != t.Family() { |
| 646 | panic(errors.AssertionFailedf("oid %d does not match %s", o, family)) |
| 647 | } |
| 648 | } |
| 649 | if family == ArrayFamily || family == TupleFamily { |
| 650 | panic(errors.AssertionFailedf("cannot make non-scalar type %s", family)) |
| 651 | } |
| 652 | if family != CollatedStringFamily && locale != "" { |
| 653 | panic(errors.AssertionFailedf("non-collation type cannot have locale %s", locale)) |
| 654 | } |
| 655 | |
| 656 | timePrecisionIsSet := false |
| 657 | var intervalDurationField *IntervalDurationField |
| 658 | var geoMetadata *GeoMetadata |
| 659 | switch family { |
| 660 | case IntervalFamily: |
| 661 | intervalDurationField = &IntervalDurationField{} |
| 662 | if precision < 0 || precision > 6 { |
| 663 | panic(errors.AssertionFailedf("precision must be between 0 and 6 inclusive")) |
| 664 | } |
| 665 | timePrecisionIsSet = true |
| 666 | case TimestampFamily, TimestampTZFamily, TimeFamily, TimeTZFamily: |
| 667 | if precision < 0 || precision > 6 { |
| 668 | panic(errors.AssertionFailedf("precision must be between 0 and 6 inclusive")) |
| 669 | } |
| 670 | timePrecisionIsSet = true |
| 671 | case DecimalFamily: |
| 672 | if precision < 0 { |
| 673 | panic(errors.AssertionFailedf("negative precision is not allowed")) |
| 674 | } |
| 675 | default: |
| 676 | if precision != 0 { |
| 677 | panic(errors.AssertionFailedf("type %s cannot have precision", family)) |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | if width < 0 { |
| 682 | panic(errors.AssertionFailedf("negative width is not allowed")) |
| 683 | } |
| 684 | switch family { |
| 685 | case IntFamily: |
| 686 | switch width { |
| 687 | case 16, 32, 64: |
| 688 | default: |
| 689 | panic(errors.AssertionFailedf("invalid width %d for IntFamily type", width)) |
| 690 | } |
| 691 | case FloatFamily: |
| 692 | switch width { |
| 693 | case 32, 64: |
| 694 | default: |
| 695 | panic(errors.AssertionFailedf("invalid width %d for FloatFamily type", width)) |
| 696 | } |
| 697 | case DecimalFamily: |
| 698 | if width > precision { |
| 699 | panic(errors.AssertionFailedf( |