Advertisement
cydside

Search and use of index for string dates

Feb 7th, 2023 (edited)
220
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.81 KB | None | 0 0
  1. CREATE TABLE datetime_text(
  2.    d1 text, -- aggiungendo COLLATE NOCASE (https://dbfiddle.uk/3YDRqT6w) utilizzerà l'indice https://sqlite.org/forum/forumpost/11ea75e73c1ed7f8
  3.    d2 text
  4. );
  5.  
  6. CREATE INDEX index_d1
  7. ON datetime_text(d1);
  8.  
  9. INSERT INTO datetime_text (d1, d2) VALUES
  10. ('2023-01-16','a'),
  11. ('2023-02-12','b'),
  12. ('2023-06-02','c'),
  13. ('2023-05-05','d'),
  14. ('2023-10-08','e'),
  15. ('2023-11-03','f'),
  16. ('2023-12-23','g'),
  17. ('2023-07-21','h'),
  18. ('2023-03-30','i'),
  19. ('2023-08-28','j'),
  20. ('2023-09-22','k'),
  21. ('2023-09-25','l'),
  22. ('2023-08-14','m'),
  23. ('2023-01-31','n');
  24.  
  25. EXPLAIN QUERY PLAN SELECT * FROM datetime_text WHERE d1 = '2023-01-16';
  26.  
  27. EXPLAIN QUERY PLAN SELECT * FROM datetime_text WHERE d1 BETWEEN '2023-01-01' AND '2023-01-31';
  28.  
  29. EXPLAIN QUERY PLAN SELECT * FROM datetime_text WHERE d1 LIKE '2023-01-%';
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement