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

Method Compare

postgres/parser/json/json.go:508–544  ·  view source on GitHub ↗
(other JSON)

Source from the content-addressed store, hash-verified

506}
507
508func (j jsonObject) Compare(other JSON) (int, error) {
509 cmp := cmpJSONTypes(j.Type(), other.Type())
510 if cmp != 0 {
511 return cmp, nil
512 }
513 lenJ := j.Len()
514 lenO := other.Len()
515 if lenJ < lenO {
516 return -1, nil
517 }
518 if lenJ > lenO {
519 return 1, nil
520 }
521 // TODO(justin): we should optimize this, we don't have to decode the whole thing.
522 var err error
523 if other, err = decodeIfNeeded(other); err != nil {
524 return 0, err
525 }
526 o := other.(jsonObject)
527 for i := 0; i < lenJ; i++ {
528 cmpKey, err := j[i].k.Compare(o[i].k)
529 if err != nil {
530 return 0, err
531 }
532 if cmpKey != 0 {
533 return cmpKey, nil
534 }
535 cmpVal, err := j[i].v.Compare(o[i].v)
536 if err != nil {
537 return 0, err
538 }
539 if cmpVal != 0 {
540 return cmpVal, nil
541 }
542 }
543 return 0, nil
544}
545
546var errTrailingCharacters = pgerror.WithCandidateCode(errors.New("trailing characters after JSON document"), pgcode.InvalidTextRepresentation)
547

Callers

nothing calls this directly

Calls 7

TypeMethod · 0.95
LenMethod · 0.95
cmpJSONTypesFunction · 0.85
decodeIfNeededFunction · 0.85
TypeMethod · 0.65
LenMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected