Full answer
sql
SELECT '10' + '5' AS plus_text, '10' || '5' AS concat_text, 10 || 5 AS concat_numbers, typeof(10 || 5) AS concat_type;| plus_text | concat_text | concat_numbers | concat_type |
|---|---|---|---|
| 15 | 105 | 105 | text |
SQLite applies numeric conversion for arithmetic, so the quoted values become 10 and 5. Concatenation always yields text, even with integer operands, which the typeof column confirms. PostgreSQL is stricter: '10' + '5' resolves the unknown literals to integers and returns 15, but 10 || 5 fails because || has no integer form unless one side is text (not run here). Relying on implicit conversion makes queries engine-dependent.
sql
SELECT '10' + '5' AS plus_text, '10' || '5' AS concat_text, 10 || 5 AS concat_numbers, typeof(10 || 5) AS concat_type;Checked on SQLite 3.46.1, run twice with identical output.
Key points
- + converts to numbers
- || converts to text
- Concatenation returns text
- PostgreSQL is stricter with ||
Common mistakes
- Expecting + to concatenate
Follow-ups
- What does 'abc' + 1 return in SQLite?
- How would you build a zero-padded code from a number?
Tips
- Let the operator decide the type