Show HN: Turn CSV Files into SQL Statements for Quick Database Transfers (github.com)
This package lets you unload a CSV from a warehouse, turn that CSV into SQL statements creating a temp table and inserting data with a CLI command, and copy those SQL statements into your query editor so you can start using the data in a different warehouse. Useful for when you need to join data together that's stored in two separate data warehouses (e.g. finance and product data).
15 comments
[ 3.3 ms ] story [ 56.7 ms ] threadAlso I appreciate you pointing out what Snowflake and BigQuery have with this. I'm wondering if there's something Redshift-specific that may be useful here for larger file volumes. It is more performant to do a CSV copy, but it can be a PITA when it comes to having a role with the right permissions to copy data from the right location.
Anything else you'd recommend I look into?
bq load --autodetect --source_format=CSV mydataset.mytable ./myfile.csv
And snowflake uses INFER_SCHEMA I believe you can do this
select * from table( infer_schema( location=>'@stage/my file.csv', file_format=>'my_csv_format' ) );
Although tbh I'm not sure if that's what you're looking for. You might enjoy looking at duckdb for stuff like this. My policy when starting data engineering was to bung everything into pandas dataframes, and now my policy is to try to avoid them at all costs because they're slow and memory hungry!
echo "name,age,city John,30,New York Jane,25,Los Angeles" > example.csv
clickhouse local -q "SELECT * FROM file('example.csv') FORMAT SQLInsert" INSERT INTO table (`name`, `age`, `city`) VALUES ('John', 30, 'New York'), ('Jane', 25, 'Los Angeles');
There was a requirement that the migration didn't blow up the transaction logs on the target DBs. I thought it would be a simple affair but after much testing I had to write a tool to generate a list of all the tables in each source DB, generate format dumping bcp commands for all the tables, then bcp commands to dump the data for each table, then SQL statements to bulk import the data using both files. The MS docs were woefully unhelpful.
[1] Databend: https://docs.databend.com/guides/load-data/load-semistructur...
[2] Snowflake: https://docs.snowflake.com/en/sql-reference/sql/copy-into-ta...
[3] Data Ingestion Benchmark: https://docs.databend.com/guides/benchmark/data-ingest