Sqlite3 delete does not delete everything?

What's going on here? I would expect the next delete to remove everything from the table. Is there a fundamental misunderstanding of how sqlite3 works for me?

sqlite> .schema

CREATE TABLE ip_domain_table (ip_domain TEXT, answer TEXT, ttl INTEGER, PRIMARY KEY(ip_domain, answer, ttl));

sqlite> select count(*) from ip_domain_table where ttl < 9999999999 ;

1605343

sqlite> pragma cache_size=100000; delete from ip_domain_table where ttl < 9999999999; 

sqlite> select count(*) from ip_domain_table where ttl < 9999999999 ;

258

Q : Why does the count show "258"? Shouldn't it be 0?

If I do this, it will delete all entries as expected.

sqlite> select count(*) from ip_domain_table;

1605343

sqlite> pragma cache_size=100000; delete from ip_domain_table;

sqlite> select count(*) from ip_domain_table;

0
+3
source share
2 answers

It is important to remember that SQLite has something called type affinity , which means that each column data type is recommended only and NOT COMPLETED. All column types can store data of any type. This means that your integer column can store numbers greater than 9999999999, or even rows.

:

  • , ttl 9999999999.
  • "select * from ip_domain_table limit 1" ? ttl 9999999999, .

delete from ip_domain_table;, .

!

+3

, , ttl . , 9999999999.

, , :

DELETE FROM ip_domain_table;
0

Source: https://habr.com/ru/post/1736434/


All Articles