teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

内容の追記

2018/12/06 00:28

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,17 @@
1
1
  **解決したい問題**
2
2
  \COPYコマンドでTSVファイルのデータをインポートする方法をご教授いただきたいです。
3
3
 
4
+ **一応の解決方法**
5
+ TSVファイルをあきらめ、CSVファイルに変更しました。
6
+ 下記で一応動きました。。
7
+ ```sql
8
+ \encoding utf8
9
+
10
+ drop table access_log;
11
+ \i src/access_log.ct
12
+ \copy access_log from 'src/access_log.bz2.csv' with csv header null '' delimiter ',' quote e'"';
13
+ ```
14
+
4
15
  ```tsv
5
16
  "www.hoge.com"~"-"~"-"~"04/Sep/2018:20:38:28 +0900"~"GET"~"/index.php?q=abc&s=def%3Aghi""~"200"~"144155"~"-"~"-"
6
17
  "www.fuga.net"~"-"~"-"~"06/Sep/2018:01:37:44 +0900"~"GET"~"/index.php?id=123&q=abc def"~"301"~"294"~"a " a"~"Opera/9.27"
@@ -111,4 +122,7 @@
111
122
  ```tsv
112
123
  "www.hoge.com" "-" "-" "04/Sep/2018:20:38:28 +0900" "GET" "/index.php?q=abc&s=def%3Aghi"" "200" "144155" "-" "-"
113
124
  "www.fuga.net" "-" "-" "06/Sep/2018:01:37:44 +0900" "GET" "/index.php?id=123&q=abc def" "301" "294" "a " a" "Opera/9.27"
114
- ```
125
+ ```
126
+
127
+ **参考サイト**
128
+ [PostgreSQLのcopyではまった](http://deta.hateblo.jp/entry/2015/09/10/094157)

4

内容の追記

2018/12/06 00:28

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -74,4 +74,41 @@
74
74
 
75
75
  **環境**
76
76
  * Windows10
77
- * PostgresSQL 9.4
77
+ * PostgresSQL 9.4
78
+
79
+ ---
80
+
81
+ **追加で試したこと**
82
+ **パターン1(pattern_1.tsv)**
83
+ ```
84
+ \copy access_log from 'src/pattern_1.tsv' ( format text, delimiter ' ', quote '"' );
85
+ 2018-12-03 08:02:24 JST ERROR: COPYの引用符はCSVモードでのみ使用できます
86
+ 2018-12-03 08:02:24 JST ステートメント: COPY access_log FROM STDIN ( format text, delimiter ' ', quote '"' );
87
+ ```
88
+
89
+ **パターン2(pattern_1.tsv)**
90
+ ```
91
+ 2018-12-03 08:17:46 JST ERROR: CSV引用符が閉じていません
92
+ 2018-12-03 08:17:46 JST コンテキスト: access_logのCOPY。行番号 1: "www.hoge.com - - 04/Sep/2018:20:38:28 +0900 GET /index.php?q=abc&s=def%3Aghi" 200 144155 - -
93
+ www.fug..."
94
+ 2018-12-03 08:17:46 JST ステートメント: COPY access_log FROM STDIN ( format csv, delimiter ' ', quote '"' );
95
+ ```
96
+
97
+ **パターン3(pattern_2.tsv)**
98
+ ```
99
+ 2018-12-03 08:23:18 JST ERROR: 列"h"のデータがありません
100
+ 2018-12-03 08:23:18 JST コンテキスト: access_logのCOPY。行番号 1: ""www.hoge.com" "-" "-" "04/Sep/2018:20:38:28 +0900" "GET" "/index.php?q=abc&s=def%3Aghi"" "200" "144..."
101
+ 2018-12-03 08:23:18 JST ステートメント: COPY access_log FROM STDIN ( format csv, delimiter ' ', quote '"' );
102
+ ```
103
+
104
+ **pattern_1.tsv**
105
+ ```tsv
106
+ www.hoge.com - - 04/Sep/2018:20:38:28 +0900 GET /index.php?q=abc&s=def%3Aghi" 200 144155 - -
107
+ www.fuga.net - - 06/Sep/2018:01:37:44 +0900 GET /index.php?id=123&q=abc def 301 294 a a Opera/9.27
108
+ ```
109
+
110
+ **pattern_2.tsv**
111
+ ```tsv
112
+ "www.hoge.com" "-" "-" "04/Sep/2018:20:38:28 +0900" "GET" "/index.php?q=abc&s=def%3Aghi"" "200" "144155" "-" "-"
113
+ "www.fuga.net" "-" "-" "06/Sep/2018:01:37:44 +0900" "GET" "/index.php?id=123&q=abc def" "301" "294" "a " a" "Opera/9.27"
114
+ ```

3

文章の変更

2018/12/03 00:07

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ```
9
9
 
10
- **バッチファイル実行後のメッセージ
10
+ **バッチファイル実行後のメッセージ**
11
11
  ```cmd
12
12
  C:\Users\user\Desktop\sql>call .\parameters-windows.bat
13
13
 

2

内容の追記

2018/11/30 06:35

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -7,12 +7,28 @@
7
7
 
8
8
  ```
9
9
 
10
+ **バッチファイル実行後のメッセージ
10
11
  ```cmd
12
+ C:\Users\user\Desktop\sql>call .\parameters-windows.bat
13
+
14
+ C:\Users\user\Desktop\sql>set PGHOST=localhost
15
+
11
- rem バッチファイル実行後の表示
16
+ C:\Users\user\Desktop\sql>set PGPORT=5432
17
+
18
+ C:\Users\user\Desktop\sql>set PGDATABASE=postgres
19
+
20
+ C:\Users\user\Desktop\sql>set PGUSER=postgres
21
+
22
+ C:\Users\user\Desktop\sql>set PSQL="C:\Program Files\PostgreSQL\9.4\bin\psql"
23
+
24
+ C:\Users\user\Desktop\sql>"C:\Program Files\PostgreSQL\9.4\bin\psql" -f load.sql
12
25
  DROP TABLE
13
26
  CREATE TABLE
14
27
  COPY 0
15
28
 
29
+ C:\Users\user\Desktop\sql>pause
30
+ 続行するには何かキーを押してください . . .
31
+
16
32
  ```
17
33
 
18
34
  **バッチファイル**

1

文章の変更

2018/11/30 06:33

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -53,4 +53,9 @@
53
53
  , i text
54
54
  , j text
55
55
  );
56
- ```
56
+ ```
57
+
58
+
59
+ **環境**
60
+ * Windows10
61
+ * PostgresSQL 9.4