Two space separated fields in SELECT field list
(1) By Max (Maxulite) on 2020-07-14 13:05:14 [source]
Just by mistake typed a space instead of the comma when entering a field list for a Select statement, but noticed that Sqlite accepted it, just ignored the first one of two, so
SELECT Field1, Field2 Field3, Field4
Field1, Field3, Field4
- No third or any following participant in this space separated exception is possible, Sqlite gives an error.
- No arbitrary name possible for the first field, only a valid field name
- Absolutely equivalent behavior noticed for MySql.
Does it have some semantic meaning in the SQL world?
(2) By David Raymond (dvdraymond) on 2020-07-14 13:10:19 in reply to 1 [link] [source]
"AS" is optional when assigning an alias, so what you have there is the equivalent of SELECT Field1, Field2 AS Field3, Field4... <mutters to himself about how much he hates it when AS is intentionally omitted> (not this case, just in general)
(3) By Ryan Smith (cuz) on 2020-07-14 13:35:57 in reply to 2 [link] [source]
<mutters to himself about how much he hates it when AS is intentionally omitted> (not this case, just in general)
I get that there is an argument for "less is more" here, but the "AS" makes the human intent clear - and human-readable clarity in code has long-term benefits hard to quantify.
It also makes mistakes (like the OP posted) obvious if it breaks with form.
PS: @OP, to add - This is not SQLite's peculiarity, it's true of ALL SQL - try it in any Engine for fun.
(4) By Max (Maxulite) on 2020-07-14 13:43:58 in reply to 2 [link] [source]
Thanks, indeed it was due to the optional AS :). I suppose if my mistake was the omitting of the planned AS, I'd recognize it instantly. But both my identifiers were correct field names and the intention was to list them so I saw the requested/provided count mismatch and nothing more.