SQLite GLOB operator
'file7.txt' GLOB 'file[0-9].txt' is 1. GLOB is SQLite's case-sensitive pattern match, with shell wildcards instead of % and _.
- Category
- Conditional
- Returns
integer (1, 0 or NULL)- In this category
- 43 of 43
Syntax
expression GLOB pattern
Engine support
| Engine | Support | Notes |
|---|---|---|
| SQL Server | Different name or syntax | LIKE supports [0-9] classes; add a _CS_ collation for case |
| PostgreSQL | Different name or syntax | LIKE (case-sensitive) or ~ for character classes |
| MySQL | Different name or syntax | REGEXP, or LIKE under a _bin collation |
| SQLite | Yes | GLOB |
| Oracle | Different name or syntax | LIKE (case-sensitive) or REGEXP_LIKE |
Examples
SQLite
SELECT 'Apple' GLOB 'A*' AS a, 'Apple' GLOB 'a*' AS b, 'abc' GLOB '?b?' AS c; -- 1, 0, 1
SQLite
SELECT name FROM (SELECT 'file7.txt' AS name UNION ALL SELECT 'fileX.txt') WHERE name GLOB 'file[0-9].txt'; -- file7.txt
SQLite
SELECT '12.5' GLOB '*[^0-9.]*' AS a, '12a' GLOB '*[^0-9.]*' AS b; -- 0, 1
Good to know
- GLOB is case-sensitive: 'Apple' GLOB 'a*' is 0 while 'Apple' LIKE 'a%' is 1.
- Negated classes use ^: '12a' GLOB '*[^0-9.]*' is 1, which makes GLOB a quick test for unexpected characters.
- There is no ESCAPE clause. Match a literal * or ? with a one-character class: [*] or [?].
- GLOB 'abc*' can use an index on a column with the default BINARY collation. LIKE 'abc%' needs a NOCASE column or case_sensitive_like for that.
Questions about GLOB
GLOB or LIKE?
LIKE for case-insensitive ASCII matching with % and _. GLOB for case-sensitive matching and character classes.
Does SQLite support REGEXP?
The grammar has a REGEXP operator, but the core library ships no function behind it. The sqlite3 command-line shell loads one; applications must register their own or load an extension.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.