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

Method SQLStandardNameWithTypmod

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

1759// This function is full of special cases. See backend/utils/adt/format_type.c
1760// in Postgres.
1761func (t *T) SQLStandardNameWithTypmod(haveTypmod bool, typmod int) string {
1762 var buf strings.Builder
1763 switch t.Family() {
1764 case AnyFamily:
1765 return "anyelement"
1766 case ArrayFamily:
1767 switch t.Oid() {
1768 case oid.T_oidvector:
1769 return "oidvector"
1770 case oid.T_int2vector:
1771 return "int2vector"
1772 case oid.T_anyarray:
1773 return "anyarray"
1774 }
1775 // If we have a typemod specified then pass it down when
1776 // formatting the array type.
1777 if !haveTypmod {
1778 return t.ArrayContents().SQLStandardName() + "[]"
1779 } else {
1780 ac := t.ArrayContents()
1781 return ac.SQLStandardNameWithTypmod(haveTypmod, typmod) + "[]"
1782 }
1783 case BitFamily:
1784 if t.Oid() == oid.T_varbit {
1785 buf.WriteString("bit varying")
1786 } else {
1787 buf.WriteString("bit")
1788 }
1789 if !haveTypmod || typmod <= 0 {
1790 return buf.String()
1791 }
1792 buf.WriteString(fmt.Sprintf("(%d)", typmod))
1793 return buf.String()
1794 case BoolFamily:
1795 return "boolean"
1796 case Box2DFamily:
1797 return "box2d"
1798 case BytesFamily:
1799 return "bytea"
1800 case DateFamily:
1801 return "date"
1802 case DecimalFamily:
1803 if !haveTypmod || typmod <= 0 {
1804 return "numeric"
1805 }
1806 // The typmod of a numeric has the precision in the upper bits and the
1807 // scale in the lower bits of a 32-bit int, after subtracting 4 (the var
1808 // header size). See numeric.c.
1809 typmod -= 4
1810 return fmt.Sprintf(
1811 "numeric(%d,%d)",
1812 (typmod>>16)&0xffff,
1813 typmod&0xffff,
1814 )
1815
1816 case FloatFamily:
1817 switch t.Width() {
1818 case 32:

Callers 1

SQLStandardNameMethod · 0.95

Calls 10

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

Tested by

no test coverage detected