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

Method doRemovePath

postgres/parser/json/json.go:1792–1828  ·  view source on GitHub ↗
(path []string)

Source from the content-addressed store, hash-verified

1790}
1791
1792func (j jsonArray) doRemovePath(path []string) (JSON, bool, error) {
1793 if len(path) == 0 {
1794 return j, false, nil
1795 }
1796 // In path-deletion we have to attempt to parse numbers (this is different
1797 // from the `-` operator, where strings just never match on arrays).
1798 idx, err := strconv.Atoi(path[0])
1799 if err != nil {
1800 // TODO(yuzefovich): give the position of the path element to match psql.
1801 err := errors.Newf("a path element is not an integer: %s", path[0])
1802 err = pgerror.WithCandidateCode(err, pgcode.InvalidTextRepresentation)
1803 return j, false, err
1804 }
1805 if len(path) == 1 {
1806 return j.RemoveIndex(idx)
1807 }
1808
1809 if idx < -len(j) || idx >= len(j) {
1810 return j, false, nil
1811 }
1812 if idx < 0 {
1813 idx += len(j)
1814 }
1815 newVal, ok, err := j[idx].doRemovePath(path[1:])
1816 if err != nil {
1817 return nil, false, err
1818 }
1819 if !ok {
1820 return j, false, nil
1821 }
1822
1823 result := make(jsonArray, len(j))
1824 copy(result, j)
1825 result[idx] = newVal
1826
1827 return result, true, nil
1828}
1829
1830func (j jsonObject) doRemovePath(path []string) (JSON, bool, error) {
1831 if len(path) == 0 {

Callers 1

RemovePathMethod · 0.95

Calls 3

RemoveIndexMethod · 0.95
WithCandidateCodeFunction · 0.92
doRemovePathMethod · 0.65

Tested by

no test coverage detected