MCPcopy Create free account
hub / github.com/dolthub/doltgresql / SQLStandardNameWithTypmod

Method SQLStandardNameWithTypmod

postgres/parser/types/types.go:1435–1599  ·  view source on GitHub ↗

SQLStandardNameWithTypmod is like SQLStandardName but it also accepts a typmod argument, and a boolean which indicates whether or not a typmod was even specified. The expected results of this function should be, in Postgres: SELECT format_type('thetype'::regype, typmod) Generally, what this does

(haveTypmod bool, typmod int)

Source from the content-addressed store, hash-verified

1433// This function is full of special cases. See backend/utils/adt/format_type.c
1434// in Postgres.
1435func (t *T) SQLStandardNameWithTypmod(haveTypmod bool, typmod int) string {
1436 var buf strings.Builder
1437 switch t.Family() {
1438 case AnyFamily:
1439 return "anyelement"
1440 case ArrayFamily:
1441 switch t.Oid() {
1442 case oid.T_oidvector:
1443 return "oidvector"
1444 case oid.T_int2vector:
1445 return "int2vector"
1446 }
1447 return t.ArrayContents().SQLStandardName() + "[]"
1448 case BitFamily:
1449 if t.Oid() == oid.T_varbit {
1450 buf.WriteString("bit varying")
1451 } else {
1452 buf.WriteString("bit")
1453 }
1454 if !haveTypmod || typmod <= 0 {
1455 return buf.String()
1456 }
1457 buf.WriteString(fmt.Sprintf("(%d)", typmod))
1458 return buf.String()
1459 case BoolFamily:
1460 return "boolean"
1461 case Box2DFamily:
1462 return "box2d"
1463 case BytesFamily:
1464 return "bytea"
1465 case DateFamily:
1466 return "date"
1467 case DecimalFamily:
1468 if !haveTypmod || typmod <= 0 {
1469 return "numeric"
1470 }
1471 // The typmod of a numeric has the precision in the upper bits and the
1472 // scale in the lower bits of a 32-bit int, after subtracting 4 (the var
1473 // header size). See numeric.c.
1474 typmod -= 4
1475 return fmt.Sprintf(
1476 "numeric(%d,%d)",
1477 (typmod>>16)&0xffff,
1478 typmod&0xffff,
1479 )
1480
1481 case FloatFamily:
1482 switch t.Width() {
1483 case 32:
1484 return "real"
1485 case 64:
1486 return "double precision"
1487 default:
1488 panic(errors.AssertionFailedf("programming error: unknown float width: %d", t.Width()))
1489 }
1490 case GeometryFamily, GeographyFamily:
1491 return t.Name() + t.InternalType.GeoMetadata.SQLString()
1492 case INetFamily:

Callers 2

SQLStandardNameMethod · 0.95
format_type.goFile · 0.80

Calls 10

FamilyMethod · 0.95
OidMethod · 0.95
ArrayContentsMethod · 0.95
WidthMethod · 0.95
NameMethod · 0.95
SQLStandardNameMethod · 0.80
WriteStringMethod · 0.80
BasenameMethod · 0.80
StringMethod · 0.65
SQLStringMethod · 0.65

Tested by

no test coverage detected