LWN.net Logo

Not sure if that's a good idea

Not sure if that's a good idea

Posted Jul 30, 2011 14:13 UTC (Sat) by Cyberax (✭ supporter ✭, #52523)
In reply to: Not sure if that's a good idea by euske
Parent article: CouchDB and SQLite creators introduce UnQL, a NoSQL query language (The H)

Actually, no. SQL is NOT a sensible language.

It's a relational query language, but it tries hard to hide its nature. For example, in a _true_ relational language such mistake should be immediately noticeable: "select a.id, b.id from table_a a, table_b b where a.some=123 and b.some>1435". It should be immediately obvious that a Cartesian product is being created (probably accidentally).

Also, SQL is way too verbose (especially treatment of NULLs), incomplete (nested grouping), real queries depend on vendor-specific features, CTEs are a poorly-designed bolt-on for tree-structured queries, etc. In short, SQL is horrible.

Want an example of a GOOD query language? Here it is: http://en.wikipedia.org/wiki/FLWOR

Ultimately, NoSQL movement may finally push the industry to design a better query language.


(Log in to post comments)

Not sure if that's a good idea

Posted Jul 30, 2011 23:56 UTC (Sat) by euske (subscriber, #9300) [Link]

My point is that, to many programmers, anything that gets their job done without much effort (i.e. learning new stuff) is considered sensible. Many people probably understand that SQL is horrible, but that does not change their behavior until there's an easier solution. It's hard for many people to "unlearn" the way of doing things once they've accustomed themselves to it.

Not sure if that's a good idea

Posted Jul 31, 2011 13:28 UTC (Sun) by endecotp (guest, #36428) [Link]

> Want an example of a GOOD query language? Here it is:
> http://en.wikipedia.org/wiki/FLWOR

It seems to be an XML thing, not relational. Can it do joins?

Not sure if that's a good idea

Posted Jul 31, 2011 13:37 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link]

Yes, it can do joins (even recursive ones) - it's trivial to prove that it's relationally complete.

In its present form FLWOR is not suited for relational databases, but I'm not claiming that we should just replace SQL with FLWOR.

However, it would be nice to see a language for database queries based on the same ideas.

Not sure if that's a good idea

Posted Jul 31, 2011 15:08 UTC (Sun) by endecotp (guest, #36428) [Link]

Hmm, OK, I see that you can have multiple "for" clauses (e.g. the last example at http://cs.au.dk/~amoeller/XML/querying/flwrexp.html).

I would still rather have something that is more like raw relational algebra though. I always find it surprising that such a thing doesn't already exist in the mainstream. I guess the problem is that SQL is "good enough".

Not sure if that's a good idea

Posted Aug 1, 2011 5:38 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

There are more subtle ways for it, you can join sub-trees using XQuery expressions and then use built-in function to create Cartesian products.

Not sure if that's a good idea

Posted Aug 2, 2011 0:54 UTC (Tue) by knobunc (subscriber, #4678) [Link]

More recent SQL makes that problem more apparent.
SELECT a.id, b.id
FROM table_a a 
JOIN table_b b XXXX
WHERE a.some = 123
  AND b.some > 1435

The syntax error from the missing text at XXXX would catch the problem.

Not that I am a SQL apologist by any stretch.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds