[sqlite] Fwd: column name as a value in a tuple - headache!

2005-11-06 Thread Bjørn Eikeland
I've been using sqlite to ease making statistical graphs from
metrological data and have encountered a strange problem.

Two columns, 'rr' and 'slag', 'rr' contains precipitation and 'slag'
contains the type of precipitation as a two letter code. RR (capital)
is the code for rain, but any and all select statemens includeing
WHERE slag="RR" fails as it thinks I'm comparing 'slag' to the column
'rr'..

Is this a feature or a bug? I'm not really sure where to look for
similar cases or what to call it. It seems it could have its uses, but
then one should also be able to force not to behave like that.

More generic example:
BEGIN TRANSACTION;
DROP TABLE test;
CREATE TABLE test(
colATEXT,
colBTEXT);
INSERT INTO test VALUES("a0", "b0");
INSERT INTO test VALUES("a1", "b1");
INSERT INTO test VALUES("a2", "b2");
INSERT INTO test VALUES("a3", "colb");
INSERT INTO test VALUES("a4", "b3");
INSERT INTO test VALUES("a5", "cola");
COMMIT;

SELECT test.* FROM test where test.colB="colb";
SELECT test.* FROM test where test.colB="cola";


I would expect each of the two queries to return a single row,
however, the first query returns 5 rows, and the last no rows.

mvh,
Bjørn


Re: [sqlite] Fwd: column name as a value in a tuple - headache!

2005-11-06 Thread Guillaume MAISON

Bjørn Eikeland a écrit :

I've been using sqlite to ease making statistical graphs from
metrological data and have encountered a strange problem.

Two columns, 'rr' and 'slag', 'rr' contains precipitation and 'slag'
contains the type of precipitation as a two letter code. RR (capital)
is the code for rain, but any and all select statemens includeing
WHERE slag="RR" fails as it thinks I'm comparing 'slag' to the column
'rr'..

Is this a feature or a bug? I'm not really sure where to look for
similar cases or what to call it. It seems it could have its uses, but
then one should also be able to force not to behave like that.


Hi Bjørn ,

Have you tried to use single quotes instead of double quotes ?

varchar values have to be encapsulated wihtin single quotes...

HTH,

--

Guillaume MAISON - [EMAIL PROTECTED]
83, Cours Victor Hugo
47000 AGEN
Tél : 05 53 87 91 48 - Fax : 05 53 68 73 50
e-mail : [EMAIL PROTECTED] - Web : http://nauteus.com



Re: [sqlite] Fwd: column name as a value in a tuple - headache!

2005-11-06 Thread Puneet Kishor


On Nov 6, 2005, at 8:19 AM, Bjørn Eikeland wrote:


Two columns, 'rr' and 'slag', 'rr' contains precipitation and 'slag'
contains the type of precipitation as a two letter code. RR (capital)
is the code for rain, but any and all select statemens includeing
WHERE slag="RR" fails as it thinks I'm comparing 'slag' to the column
'rr'..


use single quotes

WHERE slag = 'RR'




--
Puneet Kishor



Re: [sqlite] Fwd: column name as a value in a tuple - headache!

2005-11-06 Thread Bjørn Eikeland
On 11/6/05, Puneet Kishor <[EMAIL PROTECTED]> wrote:
>
> On Nov 6, 2005, at 8:19 AM, Bjørn Eikeland wrote:
>
> > Two columns, 'rr' and 'slag', 'rr' contains precipitation and 'slag'
> > contains the type of precipitation as a two letter code. RR (capital)
> > is the code for rain, but any and all select statemens includeing
> > WHERE slag="RR" fails as it thinks I'm comparing 'slag' to the column
> > 'rr'..
>
> use single quotes
>
> WHERE slag = 'RR'
>
> --
> Puneet Kishor
>
>

Single quotes it is then!

Thanks!