MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Equivalent

Method Equivalent

pkg/sql/types/types.go:1416–1453  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1414// behavior. AnyFamily types match any other type, including other AnyFamily
1415// types. And a wildcard collation (empty string) matches any other collation.
1416func (t *T) Equivalent(other *T) bool {
1417 if t.Family() == AnyFamily || other.Family() == AnyFamily {
1418 return true
1419 }
1420 if t.Family() != other.Family() {
1421 return false
1422 }
1423
1424 switch t.Family() {
1425 case CollatedStringFamily:
1426 if t.Locale() != "" && other.Locale() != "" && t.Locale() != other.Locale() {
1427 return false
1428 }
1429
1430 case TupleFamily:
1431 // If either tuple is the wildcard tuple, it's equivalent to any other
1432 // tuple type. This allows overloads to specify that they take an arbitrary
1433 // tuple type.
1434 if IsWildcardTupleType(t) || IsWildcardTupleType(other) {
1435 return true
1436 }
1437 if len(t.TupleContents()) != len(other.TupleContents()) {
1438 return false
1439 }
1440 for i := range t.TupleContents() {
1441 if !t.TupleContents()[i].Equivalent(&other.TupleContents()[i]) {
1442 return false
1443 }
1444 }
1445
1446 case ArrayFamily:
1447 if !t.ArrayContents().Equivalent(other.ArrayContents()) {
1448 return false
1449 }
1450 }
1451
1452 return true
1453}
1454
1455// Identical returns true if every field in this ColumnType is exactly the same
1456// as every corresponding field in the given ColumnType. Identical performs a

Callers 15

typeCheckOverloadedExprsFunction · 0.95
ReTypeFunction · 0.80
AppendMethod · 0.80
NewTypedUnaryExprFunction · 0.80
ArrayContainsFunction · 0.80
eval.goFile · 0.80
ensureExpectedTypeFunction · 0.80
EvalMethod · 0.80
EvalMethod · 0.80
typeCheckConstantFunction · 0.80
canConstantBecomeFunction · 0.80
TypeCheckAndRequireFunction · 0.80

Calls 5

FamilyMethod · 0.95
LocaleMethod · 0.95
TupleContentsMethod · 0.95
ArrayContentsMethod · 0.95
IsWildcardTupleTypeFunction · 0.85

Tested by

no test coverage detected