質問編集履歴
4
categoryテーブル作成のSQLに間違いがあったので修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,6 +44,7 @@
|
|
44
44
|
Count:=null;
|
45
45
|
|
46
46
|
FOR rec IN 0..loop_max LOOP
|
47
|
+
|
47
48
|
--category_wordに1つ目のカテゴリーを入れる。
|
48
49
|
select into category_word
|
49
50
|
(select split_part(category_name,E'/',1):: character varying(255) as category_name)
|
@@ -64,6 +65,7 @@
|
|
64
65
|
EXISTS(select name from category where name = category_word) and name = category_word;
|
65
66
|
|
66
67
|
loop_count:=loop_count+1;
|
68
|
+
|
67
69
|
END LOOP;
|
68
70
|
return 0;
|
69
71
|
END;
|
@@ -90,7 +92,6 @@
|
|
90
92
|
, id serial not null
|
91
93
|
, parent integer
|
92
94
|
, name character varying(255)
|
93
|
-
, name_all text
|
94
95
|
, constraint category_PKC primary key (id)
|
95
96
|
) ;
|
96
97
|
|
3
テーブル情報に記載漏れがあったので追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
・現在、10件あたりの処理に5秒ほど掛かってしまうので改善したいです。
|
7
7
|
|
8
|
-
・PREPAREやCOPY等
|
8
|
+
・PREPAREやCOPY等も調べましたが、重複処理をどうすればいいのか分からなかったです。
|
9
9
|
|
10
10
|
### 発生している問題・エラーメッセージ
|
11
11
|
|
@@ -74,8 +74,8 @@
|
|
74
74
|
```
|
75
75
|
|
76
76
|
### 試したこと
|
77
|
-
|
77
|
+
COPY文を使って1度csvで出力して、csvで読み込もうとしました。
|
78
|
-
しかし、重複チェックを
|
78
|
+
しかし、重複チェックをCOPY文でどうやればいいのか分からなくて止まっています。
|
79
79
|
|
80
80
|
### 補足情報(FW/ツールのバージョンなど)
|
81
81
|
<環境>
|
@@ -118,4 +118,20 @@
|
|
118
118
|
|
119
119
|
create unique index original_pki
|
120
120
|
on original(id);
|
121
|
+
|
122
|
+
comment on table category is 'category';
|
123
|
+
comment on column category.name_all is 'name_all';
|
124
|
+
comment on column category.id is 'id';
|
125
|
+
comment on column category.parent is 'parent';
|
126
|
+
comment on column category.name is 'name';
|
127
|
+
|
128
|
+
comment on table original is 'original';
|
129
|
+
comment on column original.id is 'id';
|
130
|
+
comment on column original.name is 'name';
|
131
|
+
comment on column original.condition_id is 'condition_id';
|
132
|
+
comment on column original.category_name is 'category_name';
|
133
|
+
comment on column original.brand is 'brand';
|
134
|
+
comment on column original.price is 'price';
|
135
|
+
comment on column original.shipping is 'shipping';
|
136
|
+
comment on column original.description is 'description';
|
121
137
|
```
|
2
コードにマークダウンを付けました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,6 +19,8 @@
|
|
19
19
|
言語:PostgreSQL
|
20
20
|
|
21
21
|
ソースコード
|
22
|
+
```lang-PostgreSQL
|
23
|
+
|
22
24
|
create or replace function insert_into_category(
|
23
25
|
Count INTEGER default null
|
24
26
|
)
|
@@ -69,6 +71,7 @@
|
|
69
71
|
|
70
72
|
select insert_into_category();
|
71
73
|
select * from category order by id asc;
|
74
|
+
```
|
72
75
|
|
73
76
|
### 試したこと
|
74
77
|
Copy文を使って1度Csvで出力して、csvで読み込もうとしました。
|
@@ -79,6 +82,8 @@
|
|
79
82
|
PostgreSql9.6,pgAdmin3
|
80
83
|
|
81
84
|
テーブルのSQL文も記載します。
|
85
|
+
```lang-PostgreSQL
|
86
|
+
|
82
87
|
--category
|
83
88
|
create table category (
|
84
89
|
name_all character varying(255)
|
@@ -112,4 +117,5 @@
|
|
112
117
|
on original(brand);
|
113
118
|
|
114
119
|
create unique index original_pki
|
115
|
-
on original(id);
|
120
|
+
on original(id);
|
121
|
+
```
|
1
使用しているテーブル情報を記載しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -76,4 +76,40 @@
|
|
76
76
|
|
77
77
|
### 補足情報(FW/ツールのバージョンなど)
|
78
78
|
<環境>
|
79
|
-
PostgreSql9.6,pgAdmin3
|
79
|
+
PostgreSql9.6,pgAdmin3
|
80
|
+
|
81
|
+
テーブルのSQL文も記載します。
|
82
|
+
--category
|
83
|
+
create table category (
|
84
|
+
name_all character varying(255)
|
85
|
+
, id serial not null
|
86
|
+
, parent integer
|
87
|
+
, name character varying(255)
|
88
|
+
, name_all text
|
89
|
+
, constraint category_PKC primary key (id)
|
90
|
+
) ;
|
91
|
+
|
92
|
+
create unique index category_pki
|
93
|
+
on category(id);
|
94
|
+
|
95
|
+
create index parent_id_index
|
96
|
+
on category(parent);
|
97
|
+
|
98
|
+
-- original
|
99
|
+
create table original (
|
100
|
+
id integer not null
|
101
|
+
, name character varying(255)
|
102
|
+
, condition_id integer
|
103
|
+
, category_name character varying(255)
|
104
|
+
, brand character varying(255)
|
105
|
+
, price double precision
|
106
|
+
, shipping integer
|
107
|
+
, description text
|
108
|
+
, constraint original_PKC primary key (id)
|
109
|
+
) ;
|
110
|
+
|
111
|
+
create index brand_index
|
112
|
+
on original(brand);
|
113
|
+
|
114
|
+
create unique index original_pki
|
115
|
+
on original(id);
|