Equivalent returns true if this type is "equivalent" to the given type. Equivalent types are compatible with one another: they can be compared, assigned, and unioned. Equivalent types must always have the same type family for the root type and any descendant types (i.e. in case of array or tuple typ
(other *T)
| 2197 | // behavior. AnyFamily types match any other type, including other AnyFamily |
| 2198 | // types. And a wildcard collation (empty string) matches any other collation. |
| 2199 | func (t *T) Equivalent(other *T) bool { |
| 2200 | if t.Family() == AnyFamily || other.Family() == AnyFamily { |
| 2201 | return true |
| 2202 | } |
| 2203 | if t.Family() != other.Family() { |
| 2204 | return false |
| 2205 | } |
| 2206 | |
| 2207 | switch t.Family() { |
| 2208 | case CollatedStringFamily: |
| 2209 | // CockroachDB differs from Postgres by comparing collation names |
| 2210 | // case-insensitively and equating hyphens/underscores. |
| 2211 | if t.Locale() != "" && other.Locale() != "" { |
| 2212 | if !lex.LocaleNamesAreEqual(t.Locale(), other.Locale()) { |
| 2213 | return false |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | case TupleFamily: |
| 2218 | // If either tuple is the wildcard tuple, it's equivalent to any other |
| 2219 | // tuple type. This allows overloads to specify that they take an arbitrary |
| 2220 | // tuple type. |
| 2221 | if IsWildcardTupleType(t) || IsWildcardTupleType(other) { |
| 2222 | return true |
| 2223 | } |
| 2224 | if len(t.TupleContents()) != len(other.TupleContents()) { |
| 2225 | return false |
| 2226 | } |
| 2227 | for i := range t.TupleContents() { |
| 2228 | if !t.TupleContents()[i].Equivalent(other.TupleContents()[i]) { |
| 2229 | return false |
| 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | case ArrayFamily: |
| 2234 | if !t.ArrayContents().Equivalent(other.ArrayContents()) { |
| 2235 | return false |
| 2236 | } |
| 2237 | |
| 2238 | case EnumFamily: |
| 2239 | // If one of the types is anyenum, then allow the comparison to |
| 2240 | // go through -- anyenum is used when matching overloads. |
| 2241 | if t.Oid() == oid.T_anyenum || other.Oid() == oid.T_anyenum { |
| 2242 | return true |
| 2243 | } |
| 2244 | if t.Oid() != other.Oid() { |
| 2245 | return false |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | return true |
| 2250 | } |
| 2251 | |
| 2252 | // EquivalentOrNull is the same as Equivalent, except it returns true if: |
| 2253 | // * `t` is Unknown (i.e., NULL) AND (allowNullTupleEquivalence OR `other` is not a tuple), |
no test coverage detected