練習從資料庫擷取資料
有了 csvkit 的威力,你不需要下載並安裝像 MS SQL Server、DB2、PgAdmin 或 TablePlus 這類花俏的資料庫管理軟體,就能存取 SQL 資料庫裡的資料。你可以直接在命令列使用 csvkit 的 sql2csv 指令來擷取資料。
在這個練習中,讓我們一步一步操作,對 SQLite 資料庫 SpotifyDatabase 中的資料表 Spotify_Popularity 套用 SQL 操作,並將查詢結果儲存為本機的 .csv 檔案 Spotify_Popularity_5Rows.csv。
本練習屬於課程
在 Shell 中進行資料處理
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Verify database name
ls
# Pull the entire Spotify_Popularity table and print in log
sql2csv --___ "___" \
--query "SELECT * FROM Spotify_Popularity"