calcArrayOid returns the OID of the array type having elements of the given type.
(elemTyp *T)
| 170 | // calcArrayOid returns the OID of the array type having elements of the given |
| 171 | // type. |
| 172 | func calcArrayOid(elemTyp *T) oid.Oid { |
| 173 | o := elemTyp.Oid() |
| 174 | switch elemTyp.Family() { |
| 175 | case ArrayFamily: |
| 176 | // Postgres nested arrays return the OID of the nested array (i.e. the |
| 177 | // OID doesn't change no matter how many levels of nesting there are), |
| 178 | // except in the special-case of the vector types. |
| 179 | switch o { |
| 180 | case oid.T_int2vector, oid.T_oidvector: |
| 181 | // Vector types have their own array OID types. |
| 182 | default: |
| 183 | return o |
| 184 | } |
| 185 | |
| 186 | case UnknownFamily: |
| 187 | // Postgres doesn't have an OID for an array of unknown values, since |
| 188 | // it's not possible to create that in Postgres. But CRDB does allow that, |
| 189 | // so return 0 for that case (since there's no T__unknown). This is what |
| 190 | // previous versions of CRDB returned for this case. |
| 191 | return unknownArrayOid |
| 192 | } |
| 193 | |
| 194 | // Map the OID of the array element type to the corresponding array OID. |
| 195 | // This should always be possible for all other OIDs (checked in oid.go |
| 196 | // init method). |
| 197 | o = oidToArrayOid[o] |
| 198 | if o == 0 { |
| 199 | panic(errors.AssertionFailedf("oid %d couldn't be mapped to array oid", o)) |
| 200 | } |
| 201 | return o |
| 202 | } |
no test coverage detected
searching dependent graphs…