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

Method downgradeType

postgres/parser/types/types.go:2174–2236  ·  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

2172// CRDB. This is necessary to preserve backwards-compatibility in mixed-version
2173// scenarios, such as during upgrade.
2174func (t *T) downgradeType() error {
2175 // Set Family and VisibleType for 19.1 backwards-compatibility.
2176 switch t.Family() {
2177 case BitFamily:
2178 if t.Oid() == oid.T_varbit {
2179 t.InternalType.VisibleType = visibleVARBIT
2180 }
2181
2182 case FloatFamily:
2183 switch t.Width() {
2184 case 32:
2185 t.InternalType.VisibleType = visibleREAL
2186 }
2187
2188 case StringFamily, CollatedStringFamily:
2189 switch t.Oid() {
2190 case oid.T_text:
2191 // Nothing to do.
2192 case oid.T_varchar:
2193 t.InternalType.VisibleType = visibleVARCHAR
2194 case oid.T_bpchar:
2195 t.InternalType.VisibleType = visibleCHAR
2196 case oid.T_char:
2197 t.InternalType.VisibleType = visibleQCHAR
2198 case oid.T_name:
2199 t.InternalType.Family = name
2200 default:
2201 return errors.AssertionFailedf("unexpected Oid: %d", t.Oid())
2202 }
2203
2204 case ArrayFamily:
2205 // Marshaling/unmarshaling nested arrays is not yet supported.
2206 if t.ArrayContents().Family() == ArrayFamily {
2207 return errors.AssertionFailedf("nested array should never be marshaled")
2208 }
2209
2210 // Downgrade to array representation used before 19.2, in which the array
2211 // type fields specified the width, locale, etc. of the element type.
2212 temp := *t.InternalType.ArrayContents
2213 if err := temp.downgradeType(); err != nil {
2214 return err
2215 }
2216 t.InternalType.Width = temp.InternalType.Width
2217 t.InternalType.Precision = temp.InternalType.Precision
2218 t.InternalType.Locale = temp.InternalType.Locale
2219 t.InternalType.VisibleType = temp.InternalType.VisibleType
2220 t.InternalType.ArrayElemType = &t.InternalType.ArrayContents.InternalType.Family
2221
2222 switch t.Oid() {
2223 case oid.T_int2vector:
2224 t.InternalType.Family = int2vector
2225 case oid.T_oidvector:
2226 t.InternalType.Family = oidvector
2227 }
2228 }
2229
2230 // Map empty locale to nil.
2231 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