PostSQL | Debug記錄

來源:互聯網
上載者:User

標籤:sql   轉換   ted   extension   問題:   方案   csv   geometry   html   

1- csv匯入postgreSQL · 問題描述:需要將csv匯入到本機資料庫,但columns很多,不想通過建立表格,並設定每個欄位名稱、類型,再用copy from複製 · 解決方案:通過python pandas包可以輕鬆將csv裡的名字和資料匯入資料庫
from sqlalchemy import create_engineimport pandas as pdengine = create_engine(‘postgresql://user:[email protected]/db_name‘)df = pd.read_csv(‘/path/to/csv_file‘)df.to_sql(‘pandas_db‘, engine
也可以添加if_exists參數,用來替換或者添加到已有的資料表,e.g.

df.to_sql(‘pandas_db‘, engine, if_exists=‘replace‘)
這個對添加文檔同樣適用。

相關文檔請見:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html 2- PostgreSQL串連postgis進行空間操作 · 問題:將column進行類型轉換,報錯

ERROR:  type "geometry" does not exist
原因是缺少postgis模組 · 解決方案: - 開啟pgadmin - 選擇工作的資料庫  - 點擊SQL添加命令 - 執行“CREATE EXTENSION postgis;”

 

持續更新...

 

PostSQL | Debug記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.