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

Function MakeScalar

pkg/sql/types/types.go:492–569  ·  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

490// MakeScalar constructs a new instance of a scalar type (i.e. not array or
491// tuple types) using the provided fields.
492func MakeScalar(family Family, o oid.Oid, precision, width int32, locale string) *T {
493 t := OidToType[o]
494 if family != t.Family() {
495 if family != CollatedStringFamily || StringFamily != t.Family() {
496 panic(errors.AssertionFailedf(
497 "oid %s does not match %s", oid.TypeName[o], family))
498 }
499 }
500 if family == ArrayFamily || family == TupleFamily {
501 panic(errors.AssertionFailedf("cannot make non-scalar type %s", family))
502 }
503 if family != CollatedStringFamily && locale != "" {
504 panic(errors.AssertionFailedf("non-collation type cannot have locale %s", locale))
505 }
506
507 timePrecisionIsSet := false
508 var intervalDurationField *IntervalDurationField
509 switch family {
510 case IntervalFamily:
511 intervalDurationField = &IntervalDurationField{}
512 if precision < 0 || precision > 6 {
513 panic(errors.AssertionFailedf("precision must be between 0 and 6 inclusive"))
514 }
515 timePrecisionIsSet = true
516 case TimestampFamily, TimestampTZFamily, TimeFamily, TimeTZFamily:
517 if precision < 0 || precision > 6 {
518 panic(errors.AssertionFailedf("precision must be between 0 and 6 inclusive"))
519 }
520 timePrecisionIsSet = true
521 case DecimalFamily:
522 if precision < 0 {
523 panic(errors.AssertionFailedf("negative precision is not allowed"))
524 }
525 default:
526 if precision != 0 {
527 panic(errors.AssertionFailedf("type %s cannot have precision", family))
528 }
529 }
530
531 if width < 0 {
532 panic(errors.AssertionFailedf("negative width is not allowed"))
533 }
534 switch family {
535 case IntFamily:
536 switch width {
537 case 16, 32, 64:
538 default:
539 panic(errors.AssertionFailedf("invalid width %d for IntFamily type", width))
540 }
541 case FloatFamily:
542 switch width {
543 case 32, 64:
544 default:
545 panic(errors.AssertionFailedf("invalid width %d for FloatFamily type", width))
546 }
547 case DecimalFamily:
548 if width > precision {
549 panic(errors.AssertionFailedf(

Callers 3

ParseMethod · 0.92
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…