LWN.net Logo

Malcolm: SQL for the command line: "show"

Malcolm: SQL for the command line: "show"

Posted Mar 24, 2009 2:48 UTC (Tue) by jordanb (guest, #45668)
Parent article: Malcolm: SQL for the command line: "show"

I find SQL to be a horrible interactive query language. So many things that should be implicit aren't. You can't say

# select gender, race, sum(income)/count(income);"

for instance. You have to say:

# select gender, race, industry sum(income)/count(id) group by gender, race, industry;

even though there's only one rational way to group the data. In fact. If you leave off any term in the group by statement, most servers will raise an error.

While there's silly redundancy in the select statement, the others have horrible and dangerous defaults, for instance this:

# delete from records;

doesn't raise an error or do nothing, which would be sensible (you didn't specify what to delete!) instead, it deletes *everything* in the table. It'd be like if 'rm's behavior without arguments was to delete every file in the current directory.

Then there's insert's annoying positional syntax, which is both tediously redundant *and* error prone. Plus the 'shortcut' way to do an insert ignores the fact that nearly every table has as its first column an auto-incrementing ID, forcing you to either go to the horrible long-form or use a non-standard workaround if you're lucky enough to be using a server that has one.

Anyway, while his tool is fairly neat I think it might have been more useful if he'd made something to coerce the data into sqlite. It'd have been less work and you don't get stuck with the shell argument escaping horror he demonstrates there.


(Log in to post comments)

Malcolm: SQL for the command line: "show"

Posted Mar 26, 2009 23:56 UTC (Thu) by zlynx (subscriber, #2285) [Link]

Insert's syntax may seem redundant for *simple* use. But if you do complicated things, it isn't.

For example, the list of values isn't limited to one thing. Values can just go on and on, inserting as many records as you like.

Or, you can put a SELECT statement there instead of VALUES.

Now what seemed redundant is necessary.

I won't argue about DELETE and UPDATE assuming all records without a WHERE being dangerous and stupid though. :-)

Malcolm: SQL for the command line: "show"

Posted Mar 27, 2009 20:09 UTC (Fri) by marcH (subscriber, #57642) [Link]

Hey, how consistent is this?
-          delete from TABLE where  ROWfilter
- select COLnames from TABLE where  ROWfilter
-          insert into TABLE values COLvalues
Every time I go back to SQL I have to google again for examples...

Higher level concerns: "Why SQL Sucks": http://perlmonks.org/?node_id=515776

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