DEV Community

Cover image for Getting a SQL Table Definition From a CSV File
Talles L
Talles L

Posted on

Getting a SQL Table Definition From a CSV File

Make sure you have sqlite3 available:

$ sudo apt install sqlite3
Enter fullscreen mode Exit fullscreen mode

Also, make sure your .csv file has a header.

Then:

$ sqlite3 <<EOF \
.mode csv \
.import "~/my_data.csv" my_table \
.schema my_table \
EOF
Enter fullscreen mode Exit fullscreen mode

Kudos to this Stack Overflow answer.

Top comments (0)