PostgreSQL copy toを利用してテーブルの特定のカラムのデータを取得する

環境
Windows 10 Home 64bit
PostgreSQL 13.2

構文
copy (select 特定のカラム from テーブル名) to 'ファイル名’;
copy toを使って特定のカラムのみデータを取得します。

操作方法
1.テーブルのデータを検索します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select * from usertbl;
uid | uname
------+--------
1234 | yamada
1231 | yamada
1232 | yamada
(3)
postgres=# select * from usertbl; uid | uname ------+-------- 1234 | yamada 1231 | yamada 1232 | yamada (3 行)
postgres=# select * from usertbl;
 uid  | uname
------+--------
 1234 | yamada
 1231 | yamada
 1232 | yamada
(3 行)

2.特定のカラムのみデータを取得します。
postgres=# copy (select uid from usertbl) to 'C:\app\result.txt’;
COPY 3

PostgreSQL

Posted by arkgame