vendredi 1 mai 2015

sqlite select AS behavior

I got a little problem with the AS in a select statement, it kinda change the type of my column from INTEGER to TEXT.

sqlite> drop table t;
sqlite> create table t (x integer);
sqlite> insert into t values (0);
sqlite> insert into t values (1);
sqlite> insert into t values (2);
sqlite> insert into t values (3);
sqlite> insert into t values (1010);
sqlite>
sqlite> .mode column t
sqlite> .headers on
sqlite> select printf('%d',x) from t order by x desc;
printf('%d',x)
--------------
1010
3
2
1
0

The sort is OK now renaming the Col to get a better header.

sqlite> select printf('%d',x) as x from t order by x desc;
x
----------
3
2
1010
1
0

The sort is no good anymore, like if doing AS make nx become a TEXT ?

Quoting don't help

sqlite> select printf('%d',x) as 'x' from t order by x desc;
x
----------
3
2
1010
1
0

Unless you stick something in the AS like this

sqlite> select printf('%d',x) as 'x ' from t order by x desc;
x
----------
1010
3
2
1
0

Is that the expected behavior ?

Thanx for any advises Cheers, Phi

Aucun commentaire:

Enregistrer un commentaire