unrecognized token
This error occurs when SQLite encounters a character or sequence it doesn't understand. Often caused by special characters, wrong quotes, or encoding issues.
The unrecognized token error means SQLite found a character sequence it can't parse.
Understanding the Error
Error: unrecognized token: "@"
Error: unrecognized token: "$"
The character or symbol isn't valid SQL syntax.
Common Causes
1. Special Characters
2. Wrong Quote Types
3. Variable Syntax From Other Languages
4. Encoding Issues
Non-ASCII characters causing problems:
5. Line Ending Issues
Windows vs Unix line endings in queries.
How to Fix It
Solution 1: Use Proper Quotes
Solution 2: Use Parameters
Solution 3: Clean the SQL String
Solution 4: Check Character Encoding
Solution 5: Type SQL Instead of Copy-Paste
Copy-pasting from documents, websites, or PDFs often introduces invisible or wrong characters.
Common Token Issues
| Token | Issue | Solution |
|-------|-------|----------|
| @ | Email addresses | Use quotes: 'email@test.com' |
| $ | Variable syntax | Use ? or :name parameters |
| # | Comments (some DBs) | Use -- or /* */ |
| \ | Escape char | Double it: \\ |
| ; | Statement end | Use only at end |
| ' ' | Smart quotes | Use ' straight quote |
Best Practices
- Use parameterized queries for all values
- Type SQL manually instead of copy-paste
- Use a SQL editor that shows invisible chars
- Check encoding if SQL comes from files
- Validate user input before building queries