Practice pushing data back to database
It is also possible to go the other way around and push local CSV files back to the database. As long as we specify the database as well as the CSV file to be loaded, csvsql
does the rest of the work for us (e.g. inferring table schema), behind the scenes.
In the following exercise, complete the command to upload Spotify_MusicAttributes.csv
as its own table in the SQLite database SpotifyDatabase
. Then, as a sanity check, re-pull the data from the newly created table in the database.
This exercise is part of the course
Data Processing in Shell
Exercise instructions
- Upload
Spotify_MusicAttributes.csv
as its own table in the SQLite databaseSpotifyDatabase
. - Re-pull the data from the newly created table
Spotify_MusicAttributes
in the SQLite databaseSpotifyDatabase
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Preview file
ls
# Upload Spotify_MusicAttributes.csv to database
csvsql --___ "sqlite:///SpotifyDatabase.db" --___ Spotify_MusicAttributes.csv
# Store SQL query as shell variable
sqlquery="SELECT * FROM Spotify_MusicAttributes"
# Apply SQL query to re-pull new table in database
sql2csv --db "sqlite:///SpotifyDatabase.db" --query "$___"