1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

psqlで繋いだ先から、データをローカルにエクスポートしたい場合

1
Last updated at Posted at 2021-01-17

概要

DBMSにPostgreSQLを利用し、psqlでDBサーバーに接続しているとき、作成したデータをローカルにエクスポートする方法を記述します。

結論

psqlで該当のDBに接続し、下記のように\copyコマンドを実行すればエクスポートできます。

\copy table_name to 'C:\Users\nannany\Desktop\sql\data.csv' with csv delimiter ',' ;

上記のコマンドでは、table_nameというテーブルのデータを、csvファイルとしてC:\Users\nannany\Desktop\sql\data.csv
にエクスポートしています。

copyコマンドではなく、\copyコマンドを利用することが肝かと思います。

参考

\copyコマンドについて

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?