← Back to SQL, page 22

sql-0433 · Medium mid

A team plans to move an app from SQLite to PostgreSQL. Which differences should they check?

Check type strictness (SQLite's flexible typing lets bad values in), date and time storage (text versus native types), booleans, auto-increment syntax, case sensitivity of LIKE and identifiers, upsert and RETURNING syntax, and functions such as strftime, ifnull and group_concat. Test queries on PostgreSQL with real data, because some differences give wrong results silently rather than errors.

Full answer

Checklist:

  • Types: SQLite accepts '12abc' in an INTEGER column; PostgreSQL rejects it. Scan columns with typeof() before migrating.
  • Dates: SQLite stores text or numbers; convert to date, timestamp or timestamptz, deciding the zone.
  • Booleans: 0 and 1 become boolean; SUM(flag) no longer works directly.
  • Keys: INTEGER PRIMARY KEY becomes bigint GENERATED ALWAYS AS IDENTITY; reset sequences after copying data.
  • Strings: LIKE is case-insensitive for ASCII in SQLite but case-sensitive in PostgreSQL (use ILIKE); || with NULL gives NULL in both.
  • Functions: strftime to to_char or date_trunc, ifnull to coalesce, group_concat to string_agg, instr to strpos.
  • Grouping: bare columns in GROUP BY queries are errors in PostgreSQL.
  • Division: integer division behaves the same, but division by zero errors in PostgreSQL instead of returning NULL.
  • Concurrency: PostgreSQL allows many writers, so code that relied on SQLite's single writer may need explicit locking.

Many of these differences are demonstrated by runs elsewhere in this bank; the checklist itself is guidance, not a run.

Key points

  • Strict types reject bad data
  • Convert dates to native types
  • Rename SQLite-only functions
  • Bare GROUP BY columns fail in PostgreSQL
  • Division by zero and LIKE case differ

Common mistakes

  • Assuming identical results because queries parse
  • Copying data without fixing sequences

Follow-ups

  • How would you verify the migrated data?
  • How would you run both databases during a transition?

Tips

  • Group the checklist by category