DuckDB export / import for a subset of tables

222 views Asked by At

Exporting and importing of all tables works great. I would like to select only a subset of tables for export. I can do COPY but that does not include the load.sql and schema.sql command files for neat importing.

1

There are 1 answers

0
Gabor Szarnyas On BEST ANSWER

As a workaround, you can use an aborted transaction to produce the scripts. For example, using plain SQL instructions:

CREATE TABLE x(t INT);
INSERT INTO x VALUES (42);
FROM x;

┌───────┐
│   t   │
│ int32 │
├───────┤
│    42 │
└───────┘

Then, start a transaction, delete the tables, export the database, then abort:

BEGIN;
DELETE FROM x;
EXPORT DATABASE 'my_database';
ABORT;

Your data will stay intact but you'll have the schema and load scripts.