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

Method downgradeType

pkg/sql/types/types.go:1805–1867  ·  view source on GitHub ↗

of the latest CRDB version. It updates the fields so that they will be marshaled into a format that is compatible with the previous version of CRDB. This is necessary to preserve backwards-compatibility in mixed-version scenarios, such as during upgrade.

()

Source from the content-addressed store, hash-verified

1803// CRDB. This is necessary to preserve backwards-compatibility in mixed-version
1804// scenarios, such as during upgrade.
1805func (t *T) downgradeType() error {
1806 // Set Family and VisibleType for 19.1 backwards-compatibility.
1807 switch t.Family() {
1808 case BitFamily:
1809 if t.Oid() == oid.T_varbit {
1810 t.InternalType.VisibleType = visibleVARBIT
1811 }
1812
1813 case FloatFamily:
1814 switch t.Width() {
1815 case 32:
1816 t.InternalType.VisibleType = visibleREAL
1817 }
1818
1819 case StringFamily, CollatedStringFamily:
1820 switch t.Oid() {
1821 case oid.T_text:
1822 // Nothing to do.
1823 case oid.T_varchar:
1824 t.InternalType.VisibleType = visibleVARCHAR
1825 case oid.T_bpchar:
1826 t.InternalType.VisibleType = visibleCHAR
1827 case oid.T_char:
1828 t.InternalType.VisibleType = visibleQCHAR
1829 case oid.T_name:
1830 t.InternalType.Family = name
1831 default:
1832 return errors.AssertionFailedf("unexpected Oid: %d", t.Oid())
1833 }
1834
1835 case ArrayFamily:
1836 // Marshaling/unmarshaling nested arrays is not yet supported.
1837 if t.ArrayContents().Family() == ArrayFamily {
1838 return errors.AssertionFailedf("nested array should never be marshaled")
1839 }
1840
1841 // Downgrade to array representation used before 19.2, in which the array
1842 // type fields specified the width, locale, etc. of the element type.
1843 temp := *t.InternalType.ArrayContents
1844 if err := temp.downgradeType(); err != nil {
1845 return err
1846 }
1847 t.InternalType.Width = temp.InternalType.Width
1848 t.InternalType.Precision = temp.InternalType.Precision
1849 t.InternalType.Locale = temp.InternalType.Locale
1850 t.InternalType.VisibleType = temp.InternalType.VisibleType
1851 t.InternalType.ArrayElemType = &t.InternalType.ArrayContents.InternalType.Family
1852
1853 switch t.Oid() {
1854 case oid.T_int2vector:
1855 t.InternalType.Family = int2vector
1856 case oid.T_oidvector:
1857 t.InternalType.Family = oidvector
1858 }
1859 }
1860
1861 // Map empty locale to nil.
1862 if t.InternalType.Locale != nil && len(*t.InternalType.Locale) == 0 {

Callers 3

SizeMethod · 0.80
MarshalMethod · 0.80
MarshalToMethod · 0.80

Calls 4

FamilyMethod · 0.95
OidMethod · 0.95
WidthMethod · 0.95
ArrayContentsMethod · 0.95

Tested by

no test coverage detected