On 2015/01/26 14:00, Tim Streater wrote:
On 26 Jan 2015 at 07:33, Hick Gunter <h...@scigames.at> wrote:

It is never a good idea to rely on automatically assigned column names. If you
want reproducible, predictable, release independant column names then please
assign them with the AS clause.
So you're saying that if I do:

   create table wiggy (a,b,c,d,e,f,g,h);

and later do:

   select a, b, c, d, e, f from wiggy;

then I should really be doing:

   select a as a, b as b, c as c, d as d, e as e, f as f from wiggy;

That'll be a bit tedious changing the more than 300 select statements in my app.

Actually yes and no... You are mixing two different problems here, namely the REQUEST and the RESULT. The first is referencing a table name and column name inside a query - this is the entire point of the SQL language and must always be understood correctly by the Engine to produce the correct result. For this, you can request: SELECT a,b FROM wiggy; and it MUST in all circumstances return exactly values found in those specific columns of that table, every time, without fail... and, the good news is: it does.

The problem as posted by the OP defines the second scenario where you use that same query (SELECT a,b FROM wiggy;) and then examine the RESULT, for example:

For every returned result, if itsResultColName=="a" then put the value in x and if 
itsResultColName=="b" then put the value*2 in y...
This is dangerous.

The correct thing would be:
For every returned result row, put the first value in x and second value*2 in 
y...

If you request first a, then b, you can and must expect it to be returned exactly like that, but expecting the name of the /result/ column headers to absolutely be "a" and "b" you may do if, and only if, you explicitly asked for it to be so (to borrow your example: SELECT a AS a, b AS b FROM wiggy; ).

Yes I know ALL SQL engines will return the correct column names for the above example queries because they are simple and it is the most obvious name to return, but please do not allow that to lure you into expecting that you can always trust the returned column name in more complex queries.


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to