WithoutTypeModifiers returns a copy of the given type with the type modifiers reset, if the type has modifiers. The returned type has arbitrary width and precision, or for some types, like timestamps, the maximum allowed width and precision. If the given type already has no type modifiers, it is ret
()
| 1437 | // precision. If the given type already has no type modifiers, it is returned |
| 1438 | // unchanged and the function does not allocate a new type. |
| 1439 | func (t *T) WithoutTypeModifiers() *T { |
| 1440 | switch t.Family() { |
| 1441 | case ArrayFamily: |
| 1442 | // Remove type modifiers of the array content type. |
| 1443 | newContents := t.ArrayContents().WithoutTypeModifiers() |
| 1444 | if newContents == t.ArrayContents() { |
| 1445 | return t |
| 1446 | } |
| 1447 | return MakeArray(newContents) |
| 1448 | case TupleFamily: |
| 1449 | // Remove type modifiers for each of the tuple content types. |
| 1450 | oldContents := t.TupleContents() |
| 1451 | newContents := make([]*T, len(oldContents)) |
| 1452 | changed := false |
| 1453 | for i := range newContents { |
| 1454 | newContents[i] = oldContents[i].WithoutTypeModifiers() |
| 1455 | if newContents[i] != oldContents[i] { |
| 1456 | changed = true |
| 1457 | } |
| 1458 | } |
| 1459 | if !changed { |
| 1460 | return t |
| 1461 | } |
| 1462 | if l := t.TupleLabels(); l != nil { |
| 1463 | return MakeLabeledTuple(newContents, l) |
| 1464 | } |
| 1465 | return MakeTuple(newContents) |
| 1466 | case EnumFamily: |
| 1467 | // Enums have no type modifiers. |
| 1468 | return t |
| 1469 | } |
| 1470 | |
| 1471 | // For types that can be a collated string, we copy the type and set the width |
| 1472 | // to 0 rather than returning the default OidToType type so that we retain the |
| 1473 | // locale value if the type is collated. |
| 1474 | if oidCanBeCollatedString(t.Oid()) { |
| 1475 | newT := *t |
| 1476 | newT.InternalType.Width = 0 |
| 1477 | return &newT |
| 1478 | } |
| 1479 | |
| 1480 | typ, ok := OidToType[t.Oid()] |
| 1481 | if !ok { |
| 1482 | // These special cases for json, json[] is here so we can |
| 1483 | // support decoding parameters with oid=json/json[] without |
| 1484 | // adding full support for these type. |
| 1485 | // TODO(sql-exp): Remove this if we support JSON. |
| 1486 | if t.Oid() == oid.T_json { |
| 1487 | return Jsonb |
| 1488 | } |
| 1489 | if t.Oid() == oid.T__json { |
| 1490 | return JSONArrayForDecodingOnly |
| 1491 | } |
| 1492 | panic(errors.AssertionFailedf("unexpected OID: %d", t.Oid())) |
| 1493 | } |
| 1494 | return typ |
| 1495 | } |
| 1496 |
no test coverage detected