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

Method SQLString

postgres/parser/types/types.go:1617–1713  ·  view source on GitHub ↗

SQLString returns the native SQL string that can be used to reproduce the type via parsing the string as a type. It is used in error messages and also to produce the output of SHOW CREATE.

()

Source from the content-addressed store, hash-verified

1615// reproduce the type via parsing the string as a type. It is used in error
1616// messages and also to produce the output of SHOW CREATE.
1617func (t *T) SQLString() string {
1618 switch t.Family() {
1619 case BitFamily:
1620 o := t.Oid()
1621 typName := "BIT"
1622 if o == oid.T_varbit {
1623 typName = "VARBIT"
1624 }
1625 // BIT(1) pretty-prints as just BIT.
1626 if (o != oid.T_varbit && t.Width() > 1) ||
1627 (o == oid.T_varbit && t.Width() > 0) {
1628 typName = fmt.Sprintf("%s(%d)", typName, t.Width())
1629 }
1630 return typName
1631 case IntFamily:
1632 switch t.Width() {
1633 case 16:
1634 return "SMALLINT" // TODO: Return commented version, different function for MySQL string -> "INT2"
1635 case 32:
1636 return "INTEGER" // TODO: Return commented version, different function for MySQL string -> "INT4"
1637 case 64:
1638 return "BIGINT" // TODO: Return commented version, different function for MySQL string -> "INT8"
1639 default:
1640 panic(errors.AssertionFailedf("programming error: unknown int width: %d", t.Width()))
1641 }
1642 case StringFamily:
1643 return t.stringTypeSQL()
1644 case CollatedStringFamily:
1645 return t.collatedStringTypeSQL(false /* isArray */)
1646 case FloatFamily:
1647 const realName = "REAL" // TODO: Return commented version, different function for MySQL string -> "FLOAT4"
1648 const doubleName = "DOUBLE PRECISION" // TODO: Return commented version, different function for MySQL string -> "FLOAT8"
1649 if t.Width() == 32 {
1650 return realName
1651 }
1652 return doubleName
1653 case DecimalFamily:
1654 if t.Precision() > 0 {
1655 if t.Width() > 0 {
1656 return fmt.Sprintf("DECIMAL(%d,%d)", t.Precision(), t.Scale())
1657 }
1658 return fmt.Sprintf("DECIMAL(%d)", t.Precision())
1659 }
1660 case JsonFamily:
1661 return "JSON"
1662 case TimestampFamily, TimestampTZFamily, TimeFamily, TimeTZFamily:
1663 if t.InternalType.Precision > 0 || t.InternalType.TimePrecisionIsSet {
1664 return fmt.Sprintf("%s(%d)", strings.ToUpper(t.Name()), t.Precision())
1665 }
1666 case GeometryFamily, GeographyFamily:
1667 return strings.ToUpper(t.Name() + t.InternalType.GeoMetadata.SQLString())
1668 case IntervalFamily:
1669 switch t.InternalType.IntervalDurationField.DurationType {
1670 case IntervalDurationType_UNSET:
1671 if t.InternalType.Precision > 0 || t.InternalType.TimePrecisionIsSet {
1672 return fmt.Sprintf("%s(%d)", strings.ToUpper(t.Name()), t.Precision())
1673 }
1674 default:

Callers 1

TelemetryNameMethod · 0.95

Calls 13

FamilyMethod · 0.95
OidMethod · 0.95
WidthMethod · 0.95
stringTypeSQLMethod · 0.95
collatedStringTypeSQLMethod · 0.95
PrecisionMethod · 0.95
ScaleMethod · 0.95
NameMethod · 0.95
ArrayContentsMethod · 0.95
TypeNameFunction · 0.92
FQNameMethod · 0.80
SQLStringMethod · 0.65

Tested by

no test coverage detected