Changeset: a1cab7d1fbff for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a1cab7d1fbff
Added Files:
        sql/test/json/Tests/shop.sql
Modified Files:
        monetdb5/modules/atoms/json.c
        sql/test/json/Tests/All
Branch: default
Log Message:

Add where-clause examples


diffs (85 lines):

diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -18,7 +18,7 @@
  */
 
 /*
- * Martin Kersten
+ * (c) 2013 Martin Kersten
  */
 #include "monetdb_config.h"
 #include "json.h"
diff --git a/sql/test/json/Tests/All b/sql/test/json/Tests/All
--- a/sql/test/json/Tests/All
+++ b/sql/test/json/Tests/All
@@ -11,3 +11,4 @@ components
 load
 aggregate00
 aggregate01
+shop
diff --git a/sql/test/json/Tests/shop.sql b/sql/test/json/Tests/shop.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/json/Tests/shop.sql
@@ -0,0 +1,60 @@
+-- based on http://goessner.net/articles/JsonPath/
+create table books(i integer, j json);
+
+insert into books values( 1, ' { 
+    "book": 
+      { "category": "reference",
+        "author": "Nigel Rees",
+        "title": "Sayings of the Century",
+        "price": 8.95
+      }}');
+
+insert into books values( 2, ' { 
+    "book": 
+      { "category": "fiction",
+        "author": "Evelyn Waugh",
+        "title": "Sword of Honour",
+        "price": 12.99
+      }}');
+
+insert into books values( 3, ' { 
+    "book": 
+      { "category": "fiction",
+        "author": "Herman Melville",
+        "title": "Moby Dick",
+        "isbn": "0-553-21311-3",
+        "price": 8.99
+      }}');
+
+insert into books values( 3, ' { 
+    "book": 
+      { "category": "fiction",
+        "author": "J. R. R. Tolkien",
+        "title": "The Lord of the Rings",
+        "isbn": "0-395-19395-8",
+        "price": 22.99
+      }}');
+
+select * from books;
+
+-- all authors of single book in the single store
+SELECT json.filter(j,'book.author') FROM books;
+SELECT json.text(json.filter(j,'book.author')) FROM books;
+
+-- a single author from the book store
+SELECT * FROM books 
+WHERE json.text(json.filter(j,'book.author')) = 'Nigel Rise';
+SELECT * FROM books 
+WHERE json.text(json.filter(j,'..author')) = 'Nigel Rise';
+
+-- numeric calculations
+SELECT * FROM books 
+WHERE json.number(json.filter(j,'book.price')) >= 12.99;
+SELECT * FROM books 
+WHERE json.number(json.filter(j,'..price')) >= 12.99;
+
+-- text pattern search
+SELECT * FROM books 
+WHERE json.text(j) like '%Tolkien%';
+
+drop table books;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to