Skip to content

Commit

Permalink
builtins: fix json_extract_path_text NULL bug
Browse files Browse the repository at this point in the history
If a null JSON is returned, then the text representation is a nil
pointer, which was not handled correctly.

No release note since this bug only exists in non-released version.

Release note: None
  • Loading branch information
rafiss committed Mar 12, 2021
1 parent 770d77c commit eed2c7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/json_builtins
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,11 @@ SELECT json_extract_path('{"a": {"b": 2}}', 'a', 'b', 'c')
----
NULL

query T
SELECT json_extract_path('null')
----
null

query T
SELECT json_extract_path_text('{"a": 1}', 'a')
----
Expand Down Expand Up @@ -649,6 +654,11 @@ SELECT json_extract_path_text('{"a": {"b": 2}}', 'a', 'b', 'c')
----
NULL

query T
SELECT json_extract_path_text('null')
----
NULL

query T
SELECT jsonb_pretty('{"a": 1}')
----
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5588,6 +5588,9 @@ var jsonExtractPathTextImpl = tree.Overload{
if err != nil {
return nil, err
}
if text == nil {
return tree.DNull, nil
}
return tree.NewDString(*text), nil
},
Info: "Returns the JSON value as text pointed to by the variadic arguments.",
Expand Down

0 comments on commit eed2c7a

Please sign in to comment.