summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorJoey Adams2010-07-23 21:13:59 +0000
committerJoey Adams2010-07-23 21:13:59 +0000
commitf5cbbbe875326dbe5d0c43bc3c692f64f77a30bd (patch)
treeaf65a7ecd05468d504710227f4d2f34a75a044a5 /sql
parentd60f4513e9490b2a0734f69f9de0bc92d8a874b4 (diff)
* JSONPath index subscript no longer extracts chars from strings.
* char() method added to JSONPath for extracting chars from strings. Although index subscripts (those using an integer) extract characters from strings in Stefan Goessner's JSONPath, and although it works that way in JavaScript, I believe it is rather illogical and unexpected in the context of JSONPath, and a poor use of the [] real estate. Because extracting characters from strings can still be useful, I have added a char() method for this. I implemented it now to prevent the supporting code for character extraction from wasting away.
Diffstat (limited to 'sql')
-rw-r--r--sql/json_path.sql55
1 files changed, 41 insertions, 14 deletions
diff --git a/sql/json_path.sql b/sql/json_path.sql
index 72a4c7e..01d972b 100644
--- a/sql/json_path.sql
+++ b/sql/json_path.sql
@@ -52,20 +52,40 @@ SELECT parse_json_path($$
[ 5 ] .. [3] . * [ * ]
$$);
-SELECT json_path($$"⁰¹\u0000³"$$, '[0]');
-SELECT json_path($$"⁰¹\u0000³"$$, '[1]');
-SELECT json_path($$"⁰¹\u0000³"$$, '[2]');
-SELECT json_path($$"⁰¹\u0000³"$$, '[3]');
-SELECT json_path('"0123"', '[-1]');
-SELECT json_path('"0123"', '[0]');
-SELECT json_path('"0123"', '[1]');
-SELECT json_path('"0123"', '[2]');
-SELECT json_path('"0123"', '[3]');
-SELECT json_path('"0123"', '[4]');
-SELECT json_path('"⁰¹²³"', '[0]');
-SELECT json_path('"⁰¹²³"', '[1]');
-SELECT json_path('"⁰¹²³"', '[2]');
-SELECT json_path('"⁰¹²³"', '[3]');
+select parse_json_path('$char');
+select parse_json_path('$.char');
+select parse_json_path('$.char()');
+select parse_json_path('$.char(5)');
+select parse_json_path('$.char( -1 )');
+select parse_json_path('$.char( -1 ) . char(0)');
+select parse_json_path('$.char( -1 ) . char ( 0 ) ');
+select parse_json_path('$.char( +1 ) . char ( 0 ) ');
+select parse_json_path('$ . char( +1 ) . char ( 0 ) ');
+select parse_json_path('$ .. char( +1 ) . char ( 0 ) ');
+select parse_json_path('$ .. char( +1 ) .. char ( 0 ) ');
+select parse_json_path('$ . char( +1 ) .. char ( 0 ) ');
+select parse_json_path('$ . char( +1 ) char ( 0 ) ');
+select parse_json_path('$ char( +1 ) char ( 0 ) ');
+select parse_json_path('char( +1 ) . char ( 0 ) ');
+select parse_json_path('.char( +1 ) . char ( 0 ) ');
+select parse_json_path('..char( +1 ) . char ( 0 ) ');
+select parse_json_path('...char( +1 ) . char ( 0 ) ');
+select parse_json_path('[char(5)]');
+
+SELECT json_path($$"⁰¹\u0000³"$$, 'char(0)');
+SELECT json_path($$"⁰¹\u0000³"$$, 'char(1)');
+SELECT json_path($$"⁰¹\u0000³"$$, 'char(2)');
+SELECT json_path($$"⁰¹\u0000³"$$, 'char(3)');
+SELECT json_path('"0123"', 'char(-1)');
+SELECT json_path('"0123"', 'char(0)');
+SELECT json_path('"0123"', 'char(1)');
+SELECT json_path('"0123"', 'char(2)');
+SELECT json_path('"0123"', 'char(3)');
+SELECT json_path('"0123"', 'char(4)');
+SELECT json_path('"⁰¹²³"', 'char(0)');
+SELECT json_path('"⁰¹²³"', 'char(1)');
+SELECT json_path('"⁰¹²³"', 'char(2)');
+SELECT json_path('"⁰¹²³"', 'char(3)');
SELECT json_path('[1,2,3]', '$');
SELECT json_path('[1,2,3]', '$.+1');
SELECT json_path('[1,2,3]', '$.-1');
@@ -144,3 +164,10 @@ SELECT json_path(json, '..[3]') FROM sample;
SELECT json_path(json, '$') FROM sample;
SELECT json_path(json, '..*') FROM sample;
+
+SELECT json_path(json, '..char(-1)') FROM sample;
+SELECT json_path(json, '..char(0)') FROM sample;
+SELECT json_path(json, '..char(1)') FROM sample;
+SELECT json_path(json, '..char(2)') FROM sample;
+SELECT json_path(json, '..char(3)') FROM sample;
+SELECT json_path(json, '..char(100)') FROM sample;