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

Function calcArrayOid

postgres/parser/types/oid.go:208–241  ·  view source on GitHub ↗

calcArrayOid returns the OID of the array type having elements of the given type.

(elemTyp *T)

Source from the content-addressed store, hash-verified

206// calcArrayOid returns the OID of the array type having elements of the given
207// type.
208func calcArrayOid(elemTyp *T) oid.Oid {
209 o := elemTyp.Oid()
210 switch elemTyp.Family() {
211 case ArrayFamily:
212 // Postgres nested arrays return the OID of the nested array (i.e. the
213 // OID doesn't change no matter how many levels of nesting there are),
214 // except in the special-case of the vector types.
215 switch o {
216 case oid.T_int2vector, oid.T_oidvector:
217 // Vector types have their own array OID types.
218 default:
219 return o
220 }
221
222 case UnknownFamily:
223 // Postgres doesn't have an OID for an array of unknown values, since
224 // it's not possible to create that in Postgres. But CRDB does allow that,
225 // so return 0 for that case (since there's no T__unknown). This is what
226 // previous versions of CRDB returned for this case.
227 return unknownArrayOid
228
229 case EnumFamily:
230 return elemTyp.UserDefinedArrayOID()
231 }
232
233 // Map the OID of the array element type to the corresponding array OID.
234 // This should always be possible for all other OIDs (checked in oid.go
235 // init method).
236 o = oidToArrayOid[o]
237 if o == 0 {
238 panic(errors.AssertionFailedf("oid %d couldn't be mapped to array oid", o))
239 }
240 return o
241}

Callers 2

MakeArrayFunction · 0.85
upgradeTypeMethod · 0.85

Calls 3

OidMethod · 0.80
FamilyMethod · 0.80
UserDefinedArrayOIDMethod · 0.80

Tested by

no test coverage detected