[xquery-talk] the stupidity of using SQL as a query language for JSON

Michael Kay mike at saxonica.com
Mon Jun 1 12:22:27 PDT 2015

> On 1 Jun 2015, at 19:08, Ihe Onwuka <ihe.onwuka at gmail.com> wrote:
> Then I have some questions.
> So what happens to the closure property.

Well, if you’re going to apply SQL to JSON (say), then the first thing you have to do is define a mapping from JSON to tables. That’s not difficult to do.

If by the “closure property” you want the result of any SQL query to be the representation of some JSON structure, then you’re not going to achieve that. That’s essentially the same as the update problem.

> Should I be allowed to join a JSON array with an object.

No, you don’t join arrays with objects (maps). You join the table representation of an array with the table representation of a map. And what you get back is a table, which of course you can query.

> Why not, or if so what type of thing will I get back and what will happen when if I try to query it (I will be allowed to query it won't I).
> If I ask to order by a field and there is no schema to tell me it's type what is SQL going to do.

JSON types are based on the syntax of the instance, not on any schema. If it looks like a number then it is a number. 4=4.0 is true, “4”=“4.0” is false.
> Talking of ordering how do I get the 5th array item or the 5th object when SQL only deals in unordered sets.

SQL doesn’t deal only in unordered sets. It deals in tables. It has an “order by” operator. You’re probably thinking of the relational model, which is not the same as SQL.
> What would be the result of union of two objects and how can I determine whether such a union should be allowed at all when there is no schema?

Again, it’s the union of two tables which are the representations of objects/maps, and the details depend on how you do the mapping.

Michael Kay
> _______________________________________________
> talk at x-query.com <mailto:talk at x-query.com>
> http://x-query.com/mailman/listinfo/talk <http://x-query.com/mailman/listinfo/talk>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20150601/4c1a7429/attachment.html>

More information about the talk mailing list