將資料寫回資料庫

在 Shell 中進行資料處理

Susan Sun

Data Person

csvsql:文件

csvsql

  • 直接在資料庫上執行 SQL 陳述式
  • 同時支援建立資料表與插入資料。

更多參數:

  • --insert
  • --db
  • --no-inference--no-constraints
在 Shell 中進行資料處理

csvsql:將資料寫回資料庫

範例語法:

csvsql --db "sqlite:///SpotifyDatabase.db" \
       --insert Spotify_MusicAttributes.csv

注意:

  1. 使用分行提升程式碼整潔與可讀性

  2. 使用三個斜線開始資料庫名稱

  3. SQLITE 資料庫以 .db 副檔名結尾

在 Shell 中進行資料處理

csvsql:將資料寫回資料庫

範例語法:

csvsql --db "sqlite:///SpotifyDatabase.db" \
       --insert Spotify_MusicAttributes.csv

文件:

csvsql -h
--insert  In addition to creating the table, also insert the
          data into the table. Only valid when --db is specified.
在 Shell 中進行資料處理

csvsql:將資料寫回資料庫

範例語法:

csvsql --no-inference --no-constraints \
       --db "sqlite:///SpotifyDatabase.db" \
       --insert Spotify_MusicAttributes.csv

文件:

csvsql -h
--no-inference   Disable type inference when parsing the input.
--no-constraints Generate a schema without length limits or null checks.
在 Shell 中進行資料處理

一起來練習吧!

在 Shell 中進行資料處理

Preparing Video For Download...