回答編集履歴

4

追記

2019/06/21 11:44

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -47,3 +47,43 @@
47
47
  ;
48
48
 
49
49
  ```
50
+
51
+ > 日付ごとに10,000行あり、そのデータの最初の100件
52
+
53
+
54
+
55
+ というと、上記だと時間的に厳しいかもしれませんね。
56
+
57
+ 以下は無名ブロックのpgsqlです。
58
+
59
+ ```SQL
60
+
61
+ DO $$ DECLARE
62
+
63
+ wr record;
64
+
65
+ BEGIN
66
+
67
+ drop table if exists item_agg;
68
+
69
+ create table item_agg(item text, item_date date);
70
+
71
+ for wr in select distinct item_date from list order by item_date
72
+
73
+ loop
74
+
75
+ insert into item_agg
76
+
77
+ select from list
78
+
79
+ where item_date=wr.item_date
80
+
81
+ order by item limit 100
82
+
83
+ ;
84
+
85
+ end loop;
86
+
87
+ END$$
88
+
89
+ ```

3

訂正

2019/06/21 11:44

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -20,9 +20,9 @@
20
20
 
21
21
  ```DATA
22
22
 
23
- create table tbl(item text, item_date date);
23
+ create table list(item text, item_date date);
24
24
 
25
- insert into tbl values
25
+ insert into list values
26
26
 
27
27
  ('aaa','2018/5/21')
28
28
 

2

訂正

2019/06/21 11:24

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```SQL
4
4
 
5
- create table itm_agg as
5
+ create table item_agg as
6
6
 
7
7
  select item_date, unnest(item_list[1:2]) as item
8
8
 

1

追記

2019/06/21 11:23

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -1,6 +1,8 @@
1
1
  一度配列として畳んで、2個だけを対象に再度配列を展開します。
2
2
 
3
3
  ```SQL
4
+
5
+ create table itm_agg as
4
6
 
5
7
  select item_date, unnest(item_list[1:2]) as item
6
8