<div dir="ltr">So SQL over JSON = Turing Tarpit.<div><br></div><div>Fair summarisation?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 1, 2015 at 5:28 PM, Michael Kay <span dir="ltr"><<a href="mailto:mike@saxonica.com" target="_blank">mike@saxonica.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span><div><br></div></span>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.</div><div><br></div><div>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.</div><div><br></div></div></blockquote><div><br></div><div>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. </div></div></div></div></div></blockquote><div><br></div></span><div>I don’t follow. You can write any query you like; it’s just that the result is a table that might not be mappable back to JSON.</div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span><blockquote type="cite"><div><div dir="ltr"><div><br></div></div></div></blockquote></span></div></div></blockquote><div>So I'm SOL if it's a date then. </div></div></div></div></div></blockquote><div><br></div></span>You won’t get any dates in the table representation of JSON, but you can get them in tables returned by a query.<span class=""><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span><blockquote type="cite"><div><div dir="ltr"><div></div><div><br></div></div></div></blockquote></span></div></div></blockquote><div>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.</div></div></div></div></div></blockquote><div><br></div></span><div>Well, a typical representation of a JSON array [“a”, “b”, “c”] might be the table</div><div><br></div><div>ARRAYS</div><div>ID       INDEX    TYPE   VALUE</div><div>001     0             String   “a”</div><div>001     1             String   “b”</div><div>001     2             String   “c”</div><div><br></div><div>and the query to get item 2 of array 001 would be</div><div><br></div><div>SELECT TYPE, VALUE FROM ARRAYS WHERE ID=001 AND INDEX=2</div><div><br></div><div>As far as I understand it this is similar to the mapping that SQL Server uses for XML.</div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><div><br></div><div>How would you  predict a priori what your table and column names would be and how many of them. </div></div></div></div></div></blockquote><div><br></div></span><div>If you’ve got no schema then you have to use a generic mapping in which the table and column names are generic concepts such as ARRAY, MAP, etc.</div><span class=""><div><br></div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div><br></div><div>If you don't can't predict the schema your semi-structured is going to generate then  how could you write your query. </div></div></div></div></blockquote><br></span></div><div>With difficulty. I can’t see anyone wanting to write it by hand.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Michael Kay</div><div>Saxonica</div></font></span></div></blockquote></div><br></div>