SQLite Forum

Different comparison results in WHERE and SELECT clauses
Login
For query:

```SQL
CREATE TABLE v0 ( v1 INTEGER PRIMARY KEY );
INSERT INTO v0 VALUES ( 9223372036854775807 );

SELECT * FROM v0 WHERE v1 >= ( 9223372036854775807 + 1 );
/* Returns 9223372036854775807 */

SELECT v1 >= ( 9223372036854775807 + 1 ) FROM v0;
/* Returns 0 */
```

We observe different comparison results on `v1 >= ( 9223372036854775807 + 1 )`, while v1 being the ROWID of the table. We are uncertain about the exact data type SQLite are using for v1 and the numerical literal, in both WHERE and SELECT clauses, so we are uncertain about the reason of the different comparison results. 

The different comparison results are also related to the PRIMARY KEY. As we remove v1 as PRIMARY KEY, the comparison results are consistent: 

```SQL
CREATE TABLE v0 ( v1 INTEGER );
INSERT INTO v0 VALUES ( 9223372036854775807 );

SELECT * FROM v0 WHERE v1 >= ( 9223372036854775807 + 1 );
/* Returns NULL */

SELECT v1 >= ( 9223372036854775807 + 1 ) FROM v0;
/* Returns 0 */
```

Looking forward to replies. And thank you for any explanation that help us to better understand this query.