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

Method upgradeType

postgres/parser/types/types.go:1950–2137  ·  view source on GitHub ↗

upgradeType assumes its input was just unmarshaled from bytes that may have been serialized by any previous version of CRDB. It upgrades the object according to the requirements of the latest version by remapping fields and setting required values. This is necessary to preserve backwards- compatibil

()

Source from the content-addressed store, hash-verified

1948// setting required values. This is necessary to preserve backwards-
1949// compatibility with older formats (e.g. restoring database from old backup).
1950func (t *T) upgradeType() error {
1951 switch t.Family() {
1952 case IntFamily:
1953 // Check VisibleType field that was populated in previous versions.
1954 switch t.InternalType.VisibleType {
1955 case visibleSMALLINT:
1956 t.InternalType.Width = 16
1957 t.InternalType.Oid = oid.T_int2
1958 case visibleINTEGER:
1959 t.InternalType.Width = 32
1960 t.InternalType.Oid = oid.T_int4
1961 case visibleBIGINT:
1962 t.InternalType.Width = 64
1963 t.InternalType.Oid = oid.T_int8
1964 case visibleBIT, visibleNONE:
1965 // Pre-2.1 BIT was using IntFamily with arbitrary widths. Clamp them
1966 // to fixed/known widths. See #34161.
1967 switch t.Width() {
1968 case 16:
1969 t.InternalType.Oid = oid.T_int2
1970 case 32:
1971 t.InternalType.Oid = oid.T_int4
1972 default:
1973 // Assume INT8 if width is 0 or not valid.
1974 t.InternalType.Oid = oid.T_int8
1975 t.InternalType.Width = 64
1976 }
1977 default:
1978 return errors.AssertionFailedf("unexpected visible type: %d", t.InternalType.VisibleType)
1979 }
1980
1981 case FloatFamily:
1982 // Map visible REAL type to 32-bit width.
1983 switch t.InternalType.VisibleType {
1984 case visibleREAL:
1985 t.InternalType.Oid = oid.T_float4
1986 t.InternalType.Width = 32
1987 case visibleDOUBLE:
1988 t.InternalType.Oid = oid.T_float8
1989 t.InternalType.Width = 64
1990 case visibleNONE:
1991 switch t.Width() {
1992 case 32:
1993 t.InternalType.Oid = oid.T_float4
1994 case 64:
1995 t.InternalType.Oid = oid.T_float8
1996 default:
1997 // Pre-2.1 (before Width) there were 3 cases:
1998 // - VisibleType = DOUBLE PRECISION, Width = 0 -> now clearly FLOAT8
1999 // - VisibleType = NONE, Width = 0 -> now clearly FLOAT8
2000 // - VisibleType = NONE, Precision > 0 -> we need to derive the width.
2001 if t.Precision() >= 1 && t.Precision() <= 24 {
2002 t.InternalType.Oid = oid.T_float4
2003 t.InternalType.Width = 32
2004 } else {
2005 t.InternalType.Oid = oid.T_float8
2006 t.InternalType.Width = 64
2007 }

Callers 1

UnmarshalMethod · 0.95

Calls 5

FamilyMethod · 0.95
WidthMethod · 0.95
PrecisionMethod · 0.95
ArrayContentsMethod · 0.95
calcArrayOidFunction · 0.85

Tested by

no test coverage detected