[sqlite] Mixing text and numeric values in comparisons

2016-03-05 Thread Igor Tandetnik
On 3/5/2016 7:48 AM, Paul van Helden wrote: > SELECT * FROM tleft, tright WHERE Txt=Flt; -- returns a match! > > Is it because of the following from https://www.sqlite.org/datatype3.html No. It is because Flt has REAL affinity, but 1.0 has no affinity. You can use CAST to explicitly give it one:

[sqlite] Mixing text and numeric values in comparisons

2016-03-05 Thread Paul van Helden
Hi again, CREATE TABLE test (A TEXT); INSERT INTO test VALUES ('1'); SELECT * FROM test WHERE A=1; -- returns 1 SELECT * FROM test WHERE A=1.0; -- returns nothing because the RHS is converted to '1.0' This would not have been a problem if CAST(1.0 AS TEXT) produced '1' (like FloatToStr does in

[sqlite] Mixing text and numeric values in comparisons

2016-03-04 Thread R Smith
On 2016/03/04 4:29 PM, Paul van Helden wrote: > On Fri, Mar 4, 2016 at 4:23 PM, Igor Tandetnik wrote: > >> On 3/4/2016 9:15 AM, Paul van Helden wrote: >> >>> So I have to detect integers in order to avoid the .0 >>> >> WHERE CAST(A as integer) = 1 >> >> > Not quite going to work either. I

[sqlite] Mixing text and numeric values in comparisons

2016-03-04 Thread Paul van Helden
On Fri, Mar 4, 2016 at 4:23 PM, Igor Tandetnik wrote: > On 3/4/2016 9:15 AM, Paul van Helden wrote: > >> So I have to detect integers in order to avoid the .0 >> > > WHERE CAST(A as integer) = 1 > > Not quite going to work either. I should have said the values are _nearly_ always integers, but

[sqlite] Mixing text and numeric values in comparisons

2016-03-04 Thread Paul van Helden
Hi Richard, Thank you for the quick reply. I cannot change the type of the column. The tables are user defined and need to be matched with other user defined tables. The values are always integers but can be in any type of column. So I have to detect integers in order to avoid the .0 How do

[sqlite] Mixing text and numeric values in comparisons

2016-03-04 Thread Paul van Helden
Hi All, CREATE TABLE test (A TEXT); INSERT INTO test VALUES ('1'); SELECT * FROM test WHERE A=1; // returns 1 SELECT * FROM test WHERE A=1.0; // returns nothing How is the second comparison done? I realize that you can have double values that are too large to convert to int64, but as I

[sqlite] Mixing text and numeric values in comparisons

2016-03-04 Thread Igor Tandetnik
On 3/4/2016 9:29 AM, Paul van Helden wrote: > On Fri, Mar 4, 2016 at 4:23 PM, Igor Tandetnik wrote: > >> On 3/4/2016 9:15 AM, Paul van Helden wrote: >> >>> So I have to detect integers in order to avoid the .0 >>> >> >> WHERE CAST(A as integer) = 1 >> >> > Not quite going to work either. I should

[sqlite] Mixing text and numeric values in comparisons

2016-03-04 Thread Igor Tandetnik
On 3/4/2016 9:15 AM, Paul van Helden wrote: > So I have to detect integers in order to avoid the .0 WHERE CAST(A as integer) = 1 -- Igor Tandetnik

[sqlite] Mixing text and numeric values in comparisons

2016-03-04 Thread Richard Hipp
On 3/4/16, Paul van Helden wrote: > Hi All, > > CREATE TABLE test (A TEXT); > INSERT INTO test VALUES ('1'); > SELECT * FROM test WHERE A=1; // returns 1 > SELECT * FROM test WHERE A=1.0; // returns nothing Because column A has type TEXT, the RHS of the = is converted to text and a text