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

Method Compare

pkg/util/json/json.go:458–494  ·  view source on GitHub ↗
(other JSON)

Source from the content-addressed store, hash-verified

456}
457
458func (j jsonObject) Compare(other JSON) (int, error) {
459 cmp := cmpJSONTypes(j.Type(), other.Type())
460 if cmp != 0 {
461 return cmp, nil
462 }
463 lenJ := j.Len()
464 lenO := other.Len()
465 if lenJ < lenO {
466 return -1, nil
467 }
468 if lenJ > lenO {
469 return 1, nil
470 }
471 // TODO(justin): we should optimize this, we don't have to decode the whole thing.
472 var err error
473 if other, err = decodeIfNeeded(other); err != nil {
474 return 0, err
475 }
476 o := other.(jsonObject)
477 for i := 0; i < lenJ; i++ {
478 cmpKey, err := j[i].k.Compare(o[i].k)
479 if err != nil {
480 return 0, err
481 }
482 if cmpKey != 0 {
483 return cmpKey, nil
484 }
485 cmpVal, err := j[i].v.Compare(o[i].v)
486 if err != nil {
487 return 0, err
488 }
489 if cmpVal != 0 {
490 return cmpVal, nil
491 }
492 }
493 return 0, nil
494}
495
496var errTrailingCharacters = pgerror.WithCandidateCode(errors.New("trailing characters after JSON document"), pgcode.InvalidTextRepresentation)
497

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