GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - nonlinearcom/pg2sqlite

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pg2sqlite.py
pg2sqlite.py
 
 
verify.py
verify.py
 
 

Repository files navigation

pg2sqlite

Postgres → SQLite converter for Directus dumps

Convert a PostgreSQL plain-text pg_dump (with COPY data) into a SQLite database — no Postgres server required. It reads the .sql dump file directly and writes a .db file.

Originally written for Directus dumps from Postgres 13, but it works for any dump that uses the same common features: standard column types, COPY ... FROM stdin data, and PRIMARY KEY / UNIQUE / FOREIGN KEY constraints driven by sequences.

Requirements

  • Python 3 (standard library only — no pip installs)
  • sqlite3 (bundled with Python)

Usage

# pg2sqlite.py <dump.sql> <database.db>
python3 pg2sqlite.py dump.sql database.db

The converter prints per-table row counts and exits non-zero if any table's row count doesn't match the dump.

Verifying a conversion

verify.py independently re-parses the raw dump and checks the SQLite output:

# verify.py <dump.sql> <database.db>
python3 verify.py dump.sql database.db

It checks table/column parity, validates every JSON value, confirms booleans are limited to 0/1/NULL, checks primary-key uniqueness, and reports any foreign-key orphans present in the source data.

Conversion rules

PostgreSQL SQLite
integer, bigint, smallint INTEGER
boolean INTEGER — values t/f → 1/0
varchar, text, uuid, json, date, timestamp*, time TEXT (stored verbatim)
numeric NUMERIC
double precision, real REAL
bytea BLOB
serial column (nextval default) INTEGER PRIMARY KEY AUTOINCREMENT

Details:

  • COPY escapes (\n, \t, \\, octal \OOO, hex \xHH, and \N → NULL) are fully decoded. Data is inserted with parameterized queries, so there is no manual SQL-string escaping to get wrong.
  • DEFAULT clauses are translated: ::type casts are stripped, true/false become 1/0, and nextval() defaults are dropped (handled by AUTOINCREMENT). CURRENT_TIMESTAMP is preserved.
  • Sequence position is carried over via AUTOINCREMENT, so new inserts continue from where the source left off.
  • Foreign keys (including ON DELETE CASCADE/SET NULL) are written into the schema but, per SQLite's default, are not enforced unless you run PRAGMA foreign_keys = ON; on the connection.
  • JSON is stored as TEXT and stays queryable via SQLite's json_*() functions.

Scope / limitations

Handles the common subset emitted by pg_dump for typical application schemas. It does not translate stored procedures, triggers, views, materialized views, CHECK constraints, generated columns, arrays, or custom/extension types (e.g. PostGIS). Dumps must be the plain text format with inline COPY data (the pg_dump default), not the custom/-Fc archive format.

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.