MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / MakeScalar

Function MakeScalar

pkg/sql/types/types.go:823–905  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

821// MakeScalar constructs a new instance of a scalar type (i.e. not array or
822// tuple types) using the provided fields.
823func MakeScalar(family Family, o oid.Oid, precision, width int32, locale string) *T {
824 t := OidToType[o]
825 if family != t.Family() {
826 if family != CollatedStringFamily || StringFamily != t.Family() {
827 panic(errors.AssertionFailedf("oid %d does not match %s", o, family))
828 }
829 }
830 if family == ArrayFamily || family == TupleFamily {
831 panic(errors.AssertionFailedf("cannot make non-scalar type %s", family))
832 }
833 if family != CollatedStringFamily && locale != "" {
834 panic(errors.AssertionFailedf("non-collation type cannot have locale %s", locale))
835 }
836
837 timePrecisionIsSet := false
838 var intervalDurationField *IntervalDurationField
839 var geoMetadata *GeoMetadata
840 switch family {
841 case IntervalFamily:
842 intervalDurationField = &IntervalDurationField{}
843 if precision < 0 || precision > 6 {
844 panic(errors.AssertionFailedf("precision must be between 0 and 6 inclusive"))
845 }
846 timePrecisionIsSet = true
847 case TimestampFamily, TimestampTZFamily, TimeFamily, TimeTZFamily:
848 if precision < 0 || precision > 6 {
849 panic(errors.AssertionFailedf("precision must be between 0 and 6 inclusive"))
850 }
851 timePrecisionIsSet = true
852 case DecimalFamily:
853 if precision < 0 {
854 panic(errors.AssertionFailedf("negative precision is not allowed"))
855 }
856 default:
857 if precision != 0 {
858 panic(errors.AssertionFailedf("type %s cannot have precision", family))
859 }
860 }
861
862 if width < 0 {
863 panic(errors.AssertionFailedf("negative width is not allowed"))
864 }
865 switch family {
866 case IntFamily:
867 switch width {
868 case 16, 32, 64:
869 default:
870 panic(errors.AssertionFailedf("invalid width %d for IntFamily type", width))
871 }
872 case FloatFamily:
873 switch width {
874 case 32, 64:
875 default:
876 panic(errors.AssertionFailedf("invalid width %d for FloatFamily type", width))
877 }
878 case DecimalFamily:
879 if width > precision {
880 panic(errors.AssertionFailedf(

Callers 2

docMethod · 0.92
FormatMethod · 0.92

Calls 1

FamilyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…