CalcArrayOid returns the OID of the array type having elements of the given type.
(elemTyp *T)
| 209 | // CalcArrayOid returns the OID of the array type having elements of the given |
| 210 | // type. |
| 211 | func CalcArrayOid(elemTyp *T) oid.Oid { |
| 212 | o := elemTyp.Oid() |
| 213 | switch elemTyp.Family() { |
| 214 | case ArrayFamily: |
| 215 | // Postgres nested arrays return the OID of the nested array (i.e. the |
| 216 | // OID doesn't change no matter how many levels of nesting there are), |
| 217 | // except in the special-case of the vector types. |
| 218 | switch o { |
| 219 | case oid.T_int2vector, oid.T_oidvector: |
| 220 | // Vector types have their own array OID types. |
| 221 | default: |
| 222 | return o |
| 223 | } |
| 224 | |
| 225 | case UnknownFamily: |
| 226 | // Postgres doesn't have an OID for an array of unknown values, since |
| 227 | // it's not possible to create that in Postgres. But CRDB does allow that, |
| 228 | // so return 0 for that case (since there's no T__unknown). This is what |
| 229 | // previous versions of CRDB returned for this case. |
| 230 | return unknownArrayOid |
| 231 | |
| 232 | case EnumFamily: |
| 233 | return elemTyp.UserDefinedArrayOID() |
| 234 | |
| 235 | case TupleFamily: |
| 236 | if elemTyp.UserDefined() { |
| 237 | if elemTyp.TypeMeta.ImplicitRecordType { |
| 238 | // We're currently not creating array types for implicitly-defined |
| 239 | // per-table record types. So, we cheat a little, and return, as the OID |
| 240 | // for an array of these things, the OID for a generic array of records. |
| 241 | return oid.T__record |
| 242 | } |
| 243 | return elemTyp.UserDefinedArrayOID() |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // Map the OID of the array element type to the corresponding array OID. |
| 248 | // This should always be possible for all other OIDs (checked in oid.go |
| 249 | // init method). |
| 250 | if o == oid.T_json { |
| 251 | o = oid.T__json |
| 252 | } else { |
| 253 | o = oidToArrayOid[o] |
| 254 | } |
| 255 | if o == 0 { |
| 256 | panic(errors.AssertionFailedf("oid %d couldn't be mapped to array oid", elemTyp.Oid())) |
| 257 | } |
| 258 | return o |
| 259 | } |
no test coverage detected
searching dependent graphs…