Skip to content

Instantly share code, notes, and snippets.

@tubackkhoa
Created February 26, 2026 10:22
Show Gist options
  • Select an option

  • Save tubackkhoa/ca1d9c1b6fb1a35933fb70cf241e45c9 to your computer and use it in GitHub Desktop.

Select an option

Save tubackkhoa/ca1d9c1b6fb1a35933fb70cf241e45c9 to your computer and use it in GitHub Desktop.
import duckdb
sqlite_file = "data/apscheduler_events.db"
duckdb_file = "data/apscheduler_events.duckdb"
con = duckdb.connect(duckdb_file)
con.execute("INSTALL sqlite;")
con.execute("LOAD sqlite;")
# get tables
tables = con.execute(
f"""
SELECT name
FROM sqlite_scan('{sqlite_file}', 'sqlite_master')
WHERE type='table'
"""
).fetchall()
for (table,) in tables:
print(f"Copying {table}")
con.execute(
f"""
CREATE TABLE "{table}" AS
SELECT * FROM sqlite_scan('{sqlite_file}', '{table}');
"""
)
con.close()
print("✅ Conversion complete")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment