Ares Ares - 4 months ago 9
SQL Question

Why does MySQL demand arguments in a specific order?

I wrestled with these two for awhile:

LOAD DATA LOCAL INFILE '...' INTO TABLE ...
FIELDS TERMINATED BY '!' LINES TERMINATED BY '\n';


That works great. What does not work, is this:

LOAD DATA LOCAL INFILE '...' INTO TABLE ...
LINES TERMINATED BY '\n' FIELDS TERMINATED BY '!';


Why not? Isn't the meaning identical? What is the rationale behind this? Are there examples where changing the order of arguments such as these changes the result?

Answer

Because that's a) the way the query engine works, and b) because the guy who wrote it didn't want to go through the hassle of coding it to allow for variable order of optional clauses with an SQL parser because that doesn't really add much value.

Ultimately, it's the same reason ls file.txt -a and file.txt -a ls aren't the same shell commands, or the reason you have to use x = 6 * (9 + 2) instead of x = 6 9 2 + * in C. The answer is because there's a syntax and it has rules.

Comments