「Tep3」を編集中

移動先: 案内検索

警告: ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。ログインまたはアカウントを作成すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。

この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 編集中の文章
122行目: 122行目:
 
% psql postgres
 
% psql postgres
 
postgres=# create database x_0226;
 
postgres=# create database x_0226;
 
 
作業用テーブルを作る
 
作業用テーブルを作る
 
% psql x_0226
 
% psql x_0226
 
x_0226=# CREATE TABLE clients(id serial, client_id int);
 
x_0226=# CREATE TABLE clients(id serial, client_id int);
 
x_0226=# CREATE TABLE others(id serial, client_id int);
 
x_0226=# CREATE TABLE others(id serial, client_id int);
 
 
エクスポートしたcsvから不要な列を削除してそれぞれにインポートする
 
エクスポートしたcsvから不要な列を削除してそれぞれにインポートする
 
x_0226=# \COPY clients(client_id) FROM '/Users/jq/3tep_gomi/clients_1.csv' WITH CSV DELIMITER ',';
 
x_0226=# \COPY clients(client_id) FROM '/Users/jq/3tep_gomi/clients_1.csv' WITH CSV DELIMITER ',';
 
x_0226=# \COPY others(client_id) FROM '/Users/jq/3tep_gomi/others_1_c.csv' WITH CSV DELIMITER ',';
 
x_0226=# \COPY others(client_id) FROM '/Users/jq/3tep_gomi/others_1_c.csv' WITH CSV DELIMITER ',';
 
+
EXCEPTを使って
EXCEPTを使ってClientsにないOthersのclient_idを拾う
 
 
x_0226=# SELECT client_id FROM others EXCEPT SELECT client_id FROM clients order by client_id asc;
 
x_0226=# SELECT client_id FROM others EXCEPT SELECT client_id FROM clients order by client_id asc;
 
作業用テーブルを作る
 
 
x_0226=# create table x_others(id serial, user_id int, note_id int, client_id int, name varchar, yomi varchar, nusi boolean, line int, generation varchar, created_at timestamp, updated_at timestamp);
 
x_0226=# create table x_others(id serial, user_id int, note_id int, client_id int, name varchar, yomi varchar, nusi boolean, line int, generation varchar, created_at timestamp, updated_at timestamp);
 
others_1.csvをインポートする
 
 
x_0226=# \COPY x_others(user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at) FROM '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',';
 
x_0226=# \COPY x_others(user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at) FROM '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',';
 
ClientsにないOthersのclient_idを含む行を削除する
 
 
x_0226=# delete from x_others where client_id in (SELECT client_id FROM others EXCEPT SELECT client_id FROM clients order by client_id asc);
 
x_0226=# delete from x_others where client_id in (SELECT client_id FROM others EXCEPT SELECT client_id FROM clients order by client_id asc);
 
エクスポート
 
 
x_0226=# \COPY (select user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at from x_others order by client_id asc) TO '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER;
 
x_0226=# \COPY (select user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at from x_others order by client_id asc) TO '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER;
 
tep3のOthersにインポートする
 
tep3_development=# \COPY others(user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at) FROM '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',';
 
 
</pre>
 
</pre>
  

wikipokpokへの投稿はすべて、クリエイティブ・コモンズ 表示-継承 (詳細はWikipokpok:著作権を参照)のもとで公開したと見なされることにご注意ください。 自分が書いたものが他の人に容赦なく編集され、自由に配布されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください。 著作権保護されている作品は、許諾なしに投稿しないでください!

このページを編集するには、下記の確認用の質問に回答してください (詳細):

取り消し | 編集の仕方 (新しいウィンドウで開きます)