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

Ihe Onwuka ihe.onwuka at gmail.com
Mon Jun 1 12:55:06 PDT 2015


On Mon, Jun 1, 2015 at 3:22 PM, Michael Kay <mike at saxonica.com> wrote:

>
> 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.
>
>
So pretty much no  subqueries (ok somebody is going to say that any query
entailing a subquery can be rewritten without one) but AFAIC  the language
you are talking about isn't really SQL then.

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.
>
>
Isn't there an impedance mismatch that has been hand-waved away somewhere
in there.


> 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.
>
>
> So I'm SOL if it's a date then.


> 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.
>
>
> Forgive me if I'm wrong. But I still don't believe I can write a statement
that gets me the 5th row of the table.


> 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.
>
>
I'm not doing the mapping. You're the one who saying it can be done.

How do you map a potentially infinitely recursive data structure into a
flat 2 dimensional table.

How would you  predict a priori what your table and column names would be
and how many of them. Say  you had two semantically different (because they
are at different levels of the hierarchy) but identically named tags what
schema is that going to generate for your tables.

If you don't can't predict the schema your semi-structured is going to
generate then  how could you write your query. Generate the tables first
and then write it when you've seen what they've produced???
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20150601/6df9b463/attachment.html>


More information about the talk mailing list