globegit-postgresql-plruby 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes +121 -0
- data/README.markdown +155 -0
- data/Rakefile +48 -0
- data/docs/plruby.rb +1931 -0
- data/ex_trans.sql +33 -0
- data/extconf.rb +267 -0
- data/plruby.html +1454 -0
- data/plruby.rd +1571 -0
- data/postgresql-plruby.gemspec +56 -0
- data/src/conversions.h +5 -0
- data/src/conversions/basic/conversions.h +25 -0
- data/src/conversions/basic/extconf.rb +8 -0
- data/src/conversions/basic/plruby_basic.c +357 -0
- data/src/conversions/bitstring/bitstring.sql +75 -0
- data/src/conversions/bitstring/conversions.h +15 -0
- data/src/conversions/bitstring/extconf.rb +8 -0
- data/src/conversions/bitstring/plruby_bitstring.c +579 -0
- data/src/conversions/convcommon.h +129 -0
- data/src/conversions/datetime/conversions.h +13 -0
- data/src/conversions/datetime/extconf.rb +8 -0
- data/src/conversions/datetime/plruby_datetime.c +269 -0
- data/src/conversions/geometry/conversions.h +37 -0
- data/src/conversions/geometry/extconf.rb +8 -0
- data/src/conversions/geometry/geometry.sql +196 -0
- data/src/conversions/geometry/plruby_geometry.c +2494 -0
- data/src/conversions/network/conversions.h +21 -0
- data/src/conversions/network/extconf.rb +8 -0
- data/src/conversions/network/network.sql +63 -0
- data/src/conversions/network/plruby_network.c +537 -0
- data/src/package.h +20 -0
- data/src/plpl.c +1708 -0
- data/src/plplan.c +893 -0
- data/src/plruby.c +1676 -0
- data/src/plruby.h +324 -0
- data/src/pltrans.c +388 -0
- data/test/conv_bitstring/b.rb +45 -0
- data/test/conv_bitstring/runtest +26 -0
- data/test/conv_bitstring/test.expected.73 +148 -0
- data/test/conv_bitstring/test.expected.74 +148 -0
- data/test/conv_bitstring/test.expected.80 +148 -0
- data/test/conv_bitstring/test.expected.81 +148 -0
- data/test/conv_bitstring/test.expected.82 +148 -0
- data/test/conv_bitstring/test.expected.83 +148 -0
- data/test/conv_bitstring/test.expected.84 +148 -0
- data/test/conv_bitstring/test.out +148 -0
- data/test/conv_bitstring/test_mklang.sql +8 -0
- data/test/conv_bitstring/test_queries.sql +63 -0
- data/test/conv_bitstring/test_queries.sql.in +63 -0
- data/test/conv_geometry/b.rb +45 -0
- data/test/conv_geometry/runtest +26 -0
- data/test/conv_geometry/test.expected.73 +265 -0
- data/test/conv_geometry/test.expected.74 +265 -0
- data/test/conv_geometry/test.expected.80 +265 -0
- data/test/conv_geometry/test.expected.81 +265 -0
- data/test/conv_geometry/test.expected.82 +265 -0
- data/test/conv_geometry/test.expected.83 +265 -0
- data/test/conv_geometry/test.expected.84 +265 -0
- data/test/conv_geometry/test.out +265 -0
- data/test/conv_geometry/test_mklang.sql +8 -0
- data/test/conv_geometry/test_queries.sql +194 -0
- data/test/conv_geometry/test_queries.sql.in +194 -0
- data/test/conv_network/b.rb +45 -0
- data/test/conv_network/runtest +26 -0
- data/test/conv_network/test.expected.73 +213 -0
- data/test/conv_network/test.expected.74 +237 -0
- data/test/conv_network/test.expected.80 +237 -0
- data/test/conv_network/test.expected.81 +237 -0
- data/test/conv_network/test.expected.82 +237 -0
- data/test/conv_network/test.expected.83 +237 -0
- data/test/conv_network/test.expected.84 +237 -0
- data/test/conv_network/test.out +237 -0
- data/test/conv_network/test_mklang.sql +8 -0
- data/test/conv_network/test_queries.sql +60 -0
- data/test/conv_network/test_queries.sql.in +60 -0
- data/test/plp/b.rb +34 -0
- data/test/plp/runtest +29 -0
- data/test/plp/test.expected.73 +472 -0
- data/test/plp/test.expected.74 +472 -0
- data/test/plp/test.expected.75 +472 -0
- data/test/plp/test.expected.80 +472 -0
- data/test/plp/test.expected.81 +472 -0
- data/test/plp/test.expected.82 +472 -0
- data/test/plp/test.expected.83 +472 -0
- data/test/plp/test.expected.84 +472 -0
- data/test/plp/test.out +472 -0
- data/test/plp/test_mklang.sql +8 -0
- data/test/plp/test_queries.sql +273 -0
- data/test/plp/test_setup.sql +931 -0
- data/test/plp/test_setup.sql.in +931 -0
- data/test/plt/b.rb +34 -0
- data/test/plt/runtest +29 -0
- data/test/plt/test.expected.73 +178 -0
- data/test/plt/test.expected.74 +178 -0
- data/test/plt/test.expected.75 +178 -0
- data/test/plt/test.expected.80 +178 -0
- data/test/plt/test.expected.81 +178 -0
- data/test/plt/test.expected.82 +178 -0
- data/test/plt/test.expected.83 +164 -0
- data/test/plt/test.expected.84 +168 -0
- data/test/plt/test.out +168 -0
- data/test/plt/test_mklang.sql +8 -0
- data/test/plt/test_queries.sql +72 -0
- data/test/plt/test_setup.sql +252 -0
- data/test/plt/test_setup.sql.in +252 -0
- data/test/range/b.rb +45 -0
- data/test/range/runtest +26 -0
- data/test/range/test.expected.73 +396 -0
- data/test/range/test.expected.73.in +396 -0
- data/test/range/test.expected.74 +396 -0
- data/test/range/test.expected.74.in +396 -0
- data/test/range/test.expected.75 +396 -0
- data/test/range/test.expected.75.in +396 -0
- data/test/range/test.expected.80 +396 -0
- data/test/range/test.expected.81 +397 -0
- data/test/range/test.expected.82 +397 -0
- data/test/range/test.expected.83 +397 -0
- data/test/range/test.expected.84 +399 -0
- data/test/range/test.out +399 -0
- data/test/range/test_mklang.sql +8 -0
- data/test/range/test_queries.sql +249 -0
- data/test/range/test_queries.sql.in +249 -0
- metadata +207 -0
@@ -0,0 +1,397 @@
|
|
1
|
+
SELECT * FROM pg_settings WHERE name LIKE 'enable%';
|
2
|
+
name | setting | category | short_desc | extra_desc | context | vartype | source | min_val | max_val
|
3
|
+
-------------------+---------+---------------------------------------------+--------------------------------------------------------+------------+---------+---------+---------+---------+---------
|
4
|
+
enable_bitmapscan | on | Query Tuning / Planner Method Configuration | Enables the planner's use of bitmap-scan plans. | | user | bool | default | |
|
5
|
+
enable_hashagg | on | Query Tuning / Planner Method Configuration | Enables the planner's use of hashed aggregation plans. | | user | bool | default | |
|
6
|
+
enable_hashjoin | on | Query Tuning / Planner Method Configuration | Enables the planner's use of hash join plans. | | user | bool | default | |
|
7
|
+
enable_indexscan | on | Query Tuning / Planner Method Configuration | Enables the planner's use of index-scan plans. | | user | bool | default | |
|
8
|
+
enable_mergejoin | on | Query Tuning / Planner Method Configuration | Enables the planner's use of merge join plans. | | user | bool | default | |
|
9
|
+
enable_nestloop | on | Query Tuning / Planner Method Configuration | Enables the planner's use of nested-loop join plans. | | user | bool | default | |
|
10
|
+
enable_seqscan | on | Query Tuning / Planner Method Configuration | Enables the planner's use of sequential-scan plans. | | user | bool | default | |
|
11
|
+
enable_sort | on | Query Tuning / Planner Method Configuration | Enables the planner's use of explicit sort steps. | | user | bool | default | |
|
12
|
+
enable_tidscan | on | Query Tuning / Planner Method Configuration | Enables the planner's use of TID scan plans. | | user | bool | default | |
|
13
|
+
(9 rows)
|
14
|
+
|
15
|
+
CREATE TABLE foo2(fooid int, f2 int);
|
16
|
+
INSERT INTO foo2 VALUES(1, 11);
|
17
|
+
INSERT INTO foo2 VALUES(2, 22);
|
18
|
+
INSERT INTO foo2 VALUES(1, 111);
|
19
|
+
CREATE FUNCTION foot(int) returns setof foo2 as '
|
20
|
+
"SELECT * FROM foo2 WHERE fooid = #{args[0]}"'
|
21
|
+
language 'plruby';
|
22
|
+
select * from foo2, foot(foo2.fooid) z where foo2.f2 = z.f2;
|
23
|
+
ERROR: function expression in FROM may not refer to other relations of same query level
|
24
|
+
select * from foo2 where f2 in (
|
25
|
+
select f2 from foot(foo2.fooid) z where z.fooid = foo2.fooid
|
26
|
+
) ORDER BY 1,2;
|
27
|
+
fooid | f2
|
28
|
+
-------+-----
|
29
|
+
1 | 11
|
30
|
+
1 | 111
|
31
|
+
2 | 22
|
32
|
+
(3 rows)
|
33
|
+
|
34
|
+
select * from foo2 where f2 in (
|
35
|
+
select f2 from foot(1) z where z.fooid = foo2.fooid
|
36
|
+
) ORDER BY 1,2;
|
37
|
+
fooid | f2
|
38
|
+
-------+-----
|
39
|
+
1 | 11
|
40
|
+
1 | 111
|
41
|
+
(2 rows)
|
42
|
+
|
43
|
+
select * from foo2 where f2 in (
|
44
|
+
select f2 from foot(foo2.fooid) z where z.fooid = 1
|
45
|
+
) ORDER BY 1,2;
|
46
|
+
fooid | f2
|
47
|
+
-------+-----
|
48
|
+
1 | 11
|
49
|
+
1 | 111
|
50
|
+
(2 rows)
|
51
|
+
|
52
|
+
select foot.fooid, foot.f2 from foot(sin(pi()/2)::int) ORDER BY 1,2;
|
53
|
+
fooid | f2
|
54
|
+
-------+-----
|
55
|
+
1 | 11
|
56
|
+
1 | 111
|
57
|
+
(2 rows)
|
58
|
+
|
59
|
+
CREATE TABLE foo (fooid int, foosubid int, fooname text, primary key(fooid,foosubid));
|
60
|
+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
|
61
|
+
INSERT INTO foo VALUES(1,1,'Joe');
|
62
|
+
INSERT INTO foo VALUES(1,2,'Ed');
|
63
|
+
INSERT INTO foo VALUES(2,1,'Mary');
|
64
|
+
CREATE FUNCTION getfoo(int) RETURNS int AS '
|
65
|
+
args[0]
|
66
|
+
' language 'plruby';
|
67
|
+
SELECT * FROM getfoo(1) AS t1;
|
68
|
+
t1
|
69
|
+
----
|
70
|
+
1
|
71
|
+
(1 row)
|
72
|
+
|
73
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
74
|
+
SELECT * FROM vw_getfoo;
|
75
|
+
getfoo
|
76
|
+
--------
|
77
|
+
1
|
78
|
+
(1 row)
|
79
|
+
|
80
|
+
DROP VIEW vw_getfoo;
|
81
|
+
DROP FUNCTION getfoo(int);
|
82
|
+
CREATE FUNCTION getfoo(int) RETURNS setof int AS '
|
83
|
+
"SELECT fooid FROM foo WHERE fooid = #{args[0]}"
|
84
|
+
' language 'plruby';
|
85
|
+
SELECT * FROM getfoo(1) AS t1;
|
86
|
+
t1
|
87
|
+
----
|
88
|
+
1
|
89
|
+
1
|
90
|
+
(2 rows)
|
91
|
+
|
92
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
93
|
+
SELECT * FROM vw_getfoo;
|
94
|
+
getfoo
|
95
|
+
--------
|
96
|
+
1
|
97
|
+
1
|
98
|
+
(2 rows)
|
99
|
+
|
100
|
+
DROP VIEW vw_getfoo;
|
101
|
+
DROP FUNCTION getfoo(int);
|
102
|
+
CREATE FUNCTION getfoo(int) RETURNS setof text AS '
|
103
|
+
"SELECT fooname FROM foo WHERE fooid = #{args[0]}"
|
104
|
+
' language 'plruby';
|
105
|
+
SELECT * FROM getfoo(1) AS t1;
|
106
|
+
t1
|
107
|
+
-----
|
108
|
+
Joe
|
109
|
+
Ed
|
110
|
+
(2 rows)
|
111
|
+
|
112
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
113
|
+
SELECT * FROM vw_getfoo;
|
114
|
+
getfoo
|
115
|
+
--------
|
116
|
+
Joe
|
117
|
+
Ed
|
118
|
+
(2 rows)
|
119
|
+
|
120
|
+
DROP VIEW vw_getfoo;
|
121
|
+
DROP FUNCTION getfoo(int);
|
122
|
+
CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
|
123
|
+
"SELECT * FROM foo WHERE fooid = #{args[0]}"
|
124
|
+
' language 'plruby';
|
125
|
+
SELECT * FROM getfoo(1) AS t1;
|
126
|
+
fooid | foosubid | fooname
|
127
|
+
-------+----------+---------
|
128
|
+
1 | 1 | Joe
|
129
|
+
1 | 2 | Ed
|
130
|
+
(2 rows)
|
131
|
+
|
132
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
133
|
+
SELECT * FROM vw_getfoo;
|
134
|
+
fooid | foosubid | fooname
|
135
|
+
-------+----------+---------
|
136
|
+
1 | 1 | Joe
|
137
|
+
1 | 2 | Ed
|
138
|
+
(2 rows)
|
139
|
+
|
140
|
+
DROP VIEW vw_getfoo;
|
141
|
+
DROP FUNCTION getfoo(int);
|
142
|
+
CREATE FUNCTION getfoo(int) RETURNS setof record AS '
|
143
|
+
"SELECT * FROM foo WHERE fooid = #{args[0]}"
|
144
|
+
' language 'plruby';
|
145
|
+
SELECT * FROM getfoo(1) AS t1(fooid int, foosubid int, fooname text);
|
146
|
+
fooid | foosubid | fooname
|
147
|
+
-------+----------+---------
|
148
|
+
1 | 1 | Joe
|
149
|
+
1 | 2 | Ed
|
150
|
+
(2 rows)
|
151
|
+
|
152
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1) AS (fooid int, foosubid int, fooname text);
|
153
|
+
SELECT * FROM vw_getfoo;
|
154
|
+
fooid | foosubid | fooname
|
155
|
+
-------+----------+---------
|
156
|
+
1 | 1 | Joe
|
157
|
+
1 | 2 | Ed
|
158
|
+
(2 rows)
|
159
|
+
|
160
|
+
DROP VIEW vw_getfoo;
|
161
|
+
DROP FUNCTION getfoo(int);
|
162
|
+
CREATE FUNCTION getfoo(int) RETURNS setof int AS '
|
163
|
+
PL.exec("SELECT fooid FROM foo WHERE fooid = #{args[0]}") do |row|
|
164
|
+
yield row.values
|
165
|
+
end
|
166
|
+
' language 'plruby';
|
167
|
+
SELECT * FROM getfoo(1) AS t1;
|
168
|
+
t1
|
169
|
+
----
|
170
|
+
1
|
171
|
+
1
|
172
|
+
(2 rows)
|
173
|
+
|
174
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
175
|
+
SELECT * FROM vw_getfoo;
|
176
|
+
getfoo
|
177
|
+
--------
|
178
|
+
1
|
179
|
+
1
|
180
|
+
(2 rows)
|
181
|
+
|
182
|
+
DROP VIEW vw_getfoo;
|
183
|
+
DROP FUNCTION getfoo(int);
|
184
|
+
CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
|
185
|
+
PL.exec("SELECT * FROM foo WHERE fooid = #{args[0]}", nil, "value") do |r|
|
186
|
+
yield r
|
187
|
+
end
|
188
|
+
' language 'plruby';
|
189
|
+
SELECT * FROM getfoo(1) AS t1;
|
190
|
+
fooid | foosubid | fooname
|
191
|
+
-------+----------+---------
|
192
|
+
1 | 1 | Joe
|
193
|
+
1 | 2 | Ed
|
194
|
+
(2 rows)
|
195
|
+
|
196
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
197
|
+
SELECT * FROM vw_getfoo;
|
198
|
+
fooid | foosubid | fooname
|
199
|
+
-------+----------+---------
|
200
|
+
1 | 1 | Joe
|
201
|
+
1 | 2 | Ed
|
202
|
+
(2 rows)
|
203
|
+
|
204
|
+
DROP VIEW vw_getfoo;
|
205
|
+
DROP FUNCTION getfoo(int);
|
206
|
+
DROP FUNCTION foot(int);
|
207
|
+
DROP TABLE foo2;
|
208
|
+
DROP TABLE foo;
|
209
|
+
CREATE TABLE foorescan (fooid int, foosubid int, fooname text, primary key(fooid,foosubid));
|
210
|
+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foorescan_pkey" for table "foorescan"
|
211
|
+
INSERT INTO foorescan values(5000,1,'abc.5000.1');
|
212
|
+
INSERT INTO foorescan values(5001,1,'abc.5001.1');
|
213
|
+
INSERT INTO foorescan values(5002,1,'abc.5002.1');
|
214
|
+
INSERT INTO foorescan values(5003,1,'abc.5003.1');
|
215
|
+
INSERT INTO foorescan values(5004,1,'abc.5004.1');
|
216
|
+
INSERT INTO foorescan values(5005,1,'abc.5005.1');
|
217
|
+
INSERT INTO foorescan values(5006,1,'abc.5006.1');
|
218
|
+
INSERT INTO foorescan values(5007,1,'abc.5007.1');
|
219
|
+
INSERT INTO foorescan values(5008,1,'abc.5008.1');
|
220
|
+
INSERT INTO foorescan values(5009,1,'abc.5009.1');
|
221
|
+
INSERT INTO foorescan values(5000,2,'abc.5000.2');
|
222
|
+
INSERT INTO foorescan values(5001,2,'abc.5001.2');
|
223
|
+
INSERT INTO foorescan values(5002,2,'abc.5002.2');
|
224
|
+
INSERT INTO foorescan values(5003,2,'abc.5003.2');
|
225
|
+
INSERT INTO foorescan values(5004,2,'abc.5004.2');
|
226
|
+
INSERT INTO foorescan values(5005,2,'abc.5005.2');
|
227
|
+
INSERT INTO foorescan values(5006,2,'abc.5006.2');
|
228
|
+
INSERT INTO foorescan values(5007,2,'abc.5007.2');
|
229
|
+
INSERT INTO foorescan values(5008,2,'abc.5008.2');
|
230
|
+
INSERT INTO foorescan values(5009,2,'abc.5009.2');
|
231
|
+
INSERT INTO foorescan values(5000,3,'abc.5000.3');
|
232
|
+
INSERT INTO foorescan values(5001,3,'abc.5001.3');
|
233
|
+
INSERT INTO foorescan values(5002,3,'abc.5002.3');
|
234
|
+
INSERT INTO foorescan values(5003,3,'abc.5003.3');
|
235
|
+
INSERT INTO foorescan values(5004,3,'abc.5004.3');
|
236
|
+
INSERT INTO foorescan values(5005,3,'abc.5005.3');
|
237
|
+
INSERT INTO foorescan values(5006,3,'abc.5006.3');
|
238
|
+
INSERT INTO foorescan values(5007,3,'abc.5007.3');
|
239
|
+
INSERT INTO foorescan values(5008,3,'abc.5008.3');
|
240
|
+
INSERT INTO foorescan values(5009,3,'abc.5009.3');
|
241
|
+
INSERT INTO foorescan values(5000,4,'abc.5000.4');
|
242
|
+
INSERT INTO foorescan values(5001,4,'abc.5001.4');
|
243
|
+
INSERT INTO foorescan values(5002,4,'abc.5002.4');
|
244
|
+
INSERT INTO foorescan values(5003,4,'abc.5003.4');
|
245
|
+
INSERT INTO foorescan values(5004,4,'abc.5004.4');
|
246
|
+
INSERT INTO foorescan values(5005,4,'abc.5005.4');
|
247
|
+
INSERT INTO foorescan values(5006,4,'abc.5006.4');
|
248
|
+
INSERT INTO foorescan values(5007,4,'abc.5007.4');
|
249
|
+
INSERT INTO foorescan values(5008,4,'abc.5008.4');
|
250
|
+
INSERT INTO foorescan values(5009,4,'abc.5009.4');
|
251
|
+
INSERT INTO foorescan values(5000,5,'abc.5000.5');
|
252
|
+
INSERT INTO foorescan values(5001,5,'abc.5001.5');
|
253
|
+
INSERT INTO foorescan values(5002,5,'abc.5002.5');
|
254
|
+
INSERT INTO foorescan values(5003,5,'abc.5003.5');
|
255
|
+
INSERT INTO foorescan values(5004,5,'abc.5004.5');
|
256
|
+
INSERT INTO foorescan values(5005,5,'abc.5005.5');
|
257
|
+
INSERT INTO foorescan values(5006,5,'abc.5006.5');
|
258
|
+
INSERT INTO foorescan values(5007,5,'abc.5007.5');
|
259
|
+
INSERT INTO foorescan values(5008,5,'abc.5008.5');
|
260
|
+
INSERT INTO foorescan values(5009,5,'abc.5009.5');
|
261
|
+
CREATE FUNCTION foorescan(int,int) RETURNS setof foorescan AS '
|
262
|
+
"SELECT * FROM foorescan WHERE fooid >= #{args[0]} and fooid < #{args[1]}"
|
263
|
+
' language 'plruby';
|
264
|
+
SELECT * FROM foorescan f WHERE f.fooid IN (
|
265
|
+
SELECT fooid FROM foorescan(5002,5004)
|
266
|
+
) ORDER BY 1,2;
|
267
|
+
fooid | foosubid | fooname
|
268
|
+
-------+----------+------------
|
269
|
+
5002 | 1 | abc.5002.1
|
270
|
+
5002 | 2 | abc.5002.2
|
271
|
+
5002 | 3 | abc.5002.3
|
272
|
+
5002 | 4 | abc.5002.4
|
273
|
+
5002 | 5 | abc.5002.5
|
274
|
+
5003 | 1 | abc.5003.1
|
275
|
+
5003 | 2 | abc.5003.2
|
276
|
+
5003 | 3 | abc.5003.3
|
277
|
+
5003 | 4 | abc.5003.4
|
278
|
+
5003 | 5 | abc.5003.5
|
279
|
+
(10 rows)
|
280
|
+
|
281
|
+
CREATE VIEW vw_foorescan AS SELECT * FROM foorescan(5002,5004);
|
282
|
+
SELECT * FROM foorescan f WHERE f.fooid IN (
|
283
|
+
SELECT fooid FROM vw_foorescan
|
284
|
+
) ORDER BY 1,2;
|
285
|
+
fooid | foosubid | fooname
|
286
|
+
-------+----------+------------
|
287
|
+
5002 | 1 | abc.5002.1
|
288
|
+
5002 | 2 | abc.5002.2
|
289
|
+
5002 | 3 | abc.5002.3
|
290
|
+
5002 | 4 | abc.5002.4
|
291
|
+
5002 | 5 | abc.5002.5
|
292
|
+
5003 | 1 | abc.5003.1
|
293
|
+
5003 | 2 | abc.5003.2
|
294
|
+
5003 | 3 | abc.5003.3
|
295
|
+
5003 | 4 | abc.5003.4
|
296
|
+
5003 | 5 | abc.5003.5
|
297
|
+
(10 rows)
|
298
|
+
|
299
|
+
CREATE TABLE barrescan (fooid int primary key);
|
300
|
+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "barrescan_pkey" for table "barrescan"
|
301
|
+
INSERT INTO barrescan values(5003);
|
302
|
+
INSERT INTO barrescan values(5004);
|
303
|
+
INSERT INTO barrescan values(5005);
|
304
|
+
INSERT INTO barrescan values(5006);
|
305
|
+
INSERT INTO barrescan values(5007);
|
306
|
+
INSERT INTO barrescan values(5008);
|
307
|
+
CREATE FUNCTION foorescan(int) RETURNS setof foorescan AS '
|
308
|
+
"SELECT * FROM foorescan WHERE fooid = #{args[0]}"
|
309
|
+
' language 'plruby';
|
310
|
+
SELECT f.* FROM barrescan b, foorescan f
|
311
|
+
WHERE f.fooid = b.fooid AND b.fooid IN (
|
312
|
+
SELECT fooid FROM foorescan(b.fooid)
|
313
|
+
) ORDER BY 1,2;
|
314
|
+
fooid | foosubid | fooname
|
315
|
+
-------+----------+------------
|
316
|
+
5003 | 1 | abc.5003.1
|
317
|
+
5003 | 2 | abc.5003.2
|
318
|
+
5003 | 3 | abc.5003.3
|
319
|
+
5003 | 4 | abc.5003.4
|
320
|
+
5003 | 5 | abc.5003.5
|
321
|
+
5004 | 1 | abc.5004.1
|
322
|
+
5004 | 2 | abc.5004.2
|
323
|
+
5004 | 3 | abc.5004.3
|
324
|
+
5004 | 4 | abc.5004.4
|
325
|
+
5004 | 5 | abc.5004.5
|
326
|
+
5005 | 1 | abc.5005.1
|
327
|
+
5005 | 2 | abc.5005.2
|
328
|
+
5005 | 3 | abc.5005.3
|
329
|
+
5005 | 4 | abc.5005.4
|
330
|
+
5005 | 5 | abc.5005.5
|
331
|
+
5006 | 1 | abc.5006.1
|
332
|
+
5006 | 2 | abc.5006.2
|
333
|
+
5006 | 3 | abc.5006.3
|
334
|
+
5006 | 4 | abc.5006.4
|
335
|
+
5006 | 5 | abc.5006.5
|
336
|
+
5007 | 1 | abc.5007.1
|
337
|
+
5007 | 2 | abc.5007.2
|
338
|
+
5007 | 3 | abc.5007.3
|
339
|
+
5007 | 4 | abc.5007.4
|
340
|
+
5007 | 5 | abc.5007.5
|
341
|
+
5008 | 1 | abc.5008.1
|
342
|
+
5008 | 2 | abc.5008.2
|
343
|
+
5008 | 3 | abc.5008.3
|
344
|
+
5008 | 4 | abc.5008.4
|
345
|
+
5008 | 5 | abc.5008.5
|
346
|
+
(30 rows)
|
347
|
+
|
348
|
+
SELECT b.fooid, max(f.foosubid) FROM barrescan b, foorescan f
|
349
|
+
WHERE f.fooid = b.fooid AND b.fooid IN (
|
350
|
+
SELECT fooid FROM foorescan(b.fooid)
|
351
|
+
) GROUP BY b.fooid ORDER BY 1,2;
|
352
|
+
fooid | max
|
353
|
+
-------+-----
|
354
|
+
5003 | 5
|
355
|
+
5004 | 5
|
356
|
+
5005 | 5
|
357
|
+
5006 | 5
|
358
|
+
5007 | 5
|
359
|
+
5008 | 5
|
360
|
+
(6 rows)
|
361
|
+
|
362
|
+
CREATE VIEW fooview1 AS SELECT f.* FROM barrescan b, foorescan f
|
363
|
+
WHERE f.fooid = b.fooid AND b.fooid IN (
|
364
|
+
SELECT fooid FROM foorescan(b.fooid)
|
365
|
+
) ORDER BY 1,2;
|
366
|
+
SELECT * FROM fooview1 AS fv WHERE fv.fooid = 5004;
|
367
|
+
fooid | foosubid | fooname
|
368
|
+
-------+----------+------------
|
369
|
+
5004 | 1 | abc.5004.1
|
370
|
+
5004 | 2 | abc.5004.2
|
371
|
+
5004 | 3 | abc.5004.3
|
372
|
+
5004 | 4 | abc.5004.4
|
373
|
+
5004 | 5 | abc.5004.5
|
374
|
+
(5 rows)
|
375
|
+
|
376
|
+
CREATE VIEW fooview2 AS SELECT b.fooid, max(f.foosubid) AS maxsubid
|
377
|
+
FROM barrescan b, foorescan f WHERE f.fooid = b.fooid AND b.fooid IN (
|
378
|
+
SELECT fooid FROM foorescan(b.fooid)
|
379
|
+
) GROUP BY b.fooid ORDER BY 1,2;
|
380
|
+
SELECT * FROM fooview2 AS fv WHERE fv.maxsubid = 5;
|
381
|
+
fooid | maxsubid
|
382
|
+
-------+----------
|
383
|
+
5003 | 5
|
384
|
+
5004 | 5
|
385
|
+
5005 | 5
|
386
|
+
5006 | 5
|
387
|
+
5007 | 5
|
388
|
+
5008 | 5
|
389
|
+
(6 rows)
|
390
|
+
|
391
|
+
DROP VIEW vw_foorescan;
|
392
|
+
DROP VIEW fooview1;
|
393
|
+
DROP VIEW fooview2;
|
394
|
+
DROP FUNCTION foorescan(int,int);
|
395
|
+
DROP FUNCTION foorescan(int);
|
396
|
+
DROP TABLE foorescan;
|
397
|
+
DROP TABLE barrescan;
|
@@ -0,0 +1,397 @@
|
|
1
|
+
SELECT * FROM pg_settings WHERE name LIKE 'enable%';
|
2
|
+
name | setting | unit | category | short_desc | extra_desc | context | vartype | source | min_val | max_val
|
3
|
+
-------------------+---------+------+---------------------------------------------+--------------------------------------------------------+------------+---------+---------+---------+---------+---------
|
4
|
+
enable_bitmapscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of bitmap-scan plans. | | user | bool | default | |
|
5
|
+
enable_hashagg | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of hashed aggregation plans. | | user | bool | default | |
|
6
|
+
enable_hashjoin | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of hash join plans. | | user | bool | default | |
|
7
|
+
enable_indexscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of index-scan plans. | | user | bool | default | |
|
8
|
+
enable_mergejoin | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of merge join plans. | | user | bool | default | |
|
9
|
+
enable_nestloop | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of nested-loop join plans. | | user | bool | default | |
|
10
|
+
enable_seqscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of sequential-scan plans. | | user | bool | default | |
|
11
|
+
enable_sort | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of explicit sort steps. | | user | bool | default | |
|
12
|
+
enable_tidscan | on | | Query Tuning / Planner Method Configuration | Enables the planner's use of TID scan plans. | | user | bool | default | |
|
13
|
+
(9 rows)
|
14
|
+
|
15
|
+
CREATE TABLE foo2(fooid int, f2 int);
|
16
|
+
INSERT INTO foo2 VALUES(1, 11);
|
17
|
+
INSERT INTO foo2 VALUES(2, 22);
|
18
|
+
INSERT INTO foo2 VALUES(1, 111);
|
19
|
+
CREATE FUNCTION foot(int) returns setof foo2 as '
|
20
|
+
"SELECT * FROM foo2 WHERE fooid = #{args[0]}"'
|
21
|
+
language 'plruby';
|
22
|
+
select * from foo2, foot(foo2.fooid) z where foo2.f2 = z.f2;
|
23
|
+
ERROR: function expression in FROM may not refer to other relations of same query level
|
24
|
+
select * from foo2 where f2 in (
|
25
|
+
select f2 from foot(foo2.fooid) z where z.fooid = foo2.fooid
|
26
|
+
) ORDER BY 1,2;
|
27
|
+
fooid | f2
|
28
|
+
-------+-----
|
29
|
+
1 | 11
|
30
|
+
1 | 111
|
31
|
+
2 | 22
|
32
|
+
(3 rows)
|
33
|
+
|
34
|
+
select * from foo2 where f2 in (
|
35
|
+
select f2 from foot(1) z where z.fooid = foo2.fooid
|
36
|
+
) ORDER BY 1,2;
|
37
|
+
fooid | f2
|
38
|
+
-------+-----
|
39
|
+
1 | 11
|
40
|
+
1 | 111
|
41
|
+
(2 rows)
|
42
|
+
|
43
|
+
select * from foo2 where f2 in (
|
44
|
+
select f2 from foot(foo2.fooid) z where z.fooid = 1
|
45
|
+
) ORDER BY 1,2;
|
46
|
+
fooid | f2
|
47
|
+
-------+-----
|
48
|
+
1 | 11
|
49
|
+
1 | 111
|
50
|
+
(2 rows)
|
51
|
+
|
52
|
+
select foot.fooid, foot.f2 from foot(sin(pi()/2)::int) ORDER BY 1,2;
|
53
|
+
fooid | f2
|
54
|
+
-------+-----
|
55
|
+
1 | 11
|
56
|
+
1 | 111
|
57
|
+
(2 rows)
|
58
|
+
|
59
|
+
CREATE TABLE foo (fooid int, foosubid int, fooname text, primary key(fooid,foosubid));
|
60
|
+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
|
61
|
+
INSERT INTO foo VALUES(1,1,'Joe');
|
62
|
+
INSERT INTO foo VALUES(1,2,'Ed');
|
63
|
+
INSERT INTO foo VALUES(2,1,'Mary');
|
64
|
+
CREATE FUNCTION getfoo(int) RETURNS int AS '
|
65
|
+
args[0]
|
66
|
+
' language 'plruby';
|
67
|
+
SELECT * FROM getfoo(1) AS t1;
|
68
|
+
t1
|
69
|
+
----
|
70
|
+
1
|
71
|
+
(1 row)
|
72
|
+
|
73
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
74
|
+
SELECT * FROM vw_getfoo;
|
75
|
+
getfoo
|
76
|
+
--------
|
77
|
+
1
|
78
|
+
(1 row)
|
79
|
+
|
80
|
+
DROP VIEW vw_getfoo;
|
81
|
+
DROP FUNCTION getfoo(int);
|
82
|
+
CREATE FUNCTION getfoo(int) RETURNS setof int AS '
|
83
|
+
"SELECT fooid FROM foo WHERE fooid = #{args[0]}"
|
84
|
+
' language 'plruby';
|
85
|
+
SELECT * FROM getfoo(1) AS t1;
|
86
|
+
t1
|
87
|
+
----
|
88
|
+
1
|
89
|
+
1
|
90
|
+
(2 rows)
|
91
|
+
|
92
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
93
|
+
SELECT * FROM vw_getfoo;
|
94
|
+
getfoo
|
95
|
+
--------
|
96
|
+
1
|
97
|
+
1
|
98
|
+
(2 rows)
|
99
|
+
|
100
|
+
DROP VIEW vw_getfoo;
|
101
|
+
DROP FUNCTION getfoo(int);
|
102
|
+
CREATE FUNCTION getfoo(int) RETURNS setof text AS '
|
103
|
+
"SELECT fooname FROM foo WHERE fooid = #{args[0]}"
|
104
|
+
' language 'plruby';
|
105
|
+
SELECT * FROM getfoo(1) AS t1;
|
106
|
+
t1
|
107
|
+
-----
|
108
|
+
Joe
|
109
|
+
Ed
|
110
|
+
(2 rows)
|
111
|
+
|
112
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
113
|
+
SELECT * FROM vw_getfoo;
|
114
|
+
getfoo
|
115
|
+
--------
|
116
|
+
Joe
|
117
|
+
Ed
|
118
|
+
(2 rows)
|
119
|
+
|
120
|
+
DROP VIEW vw_getfoo;
|
121
|
+
DROP FUNCTION getfoo(int);
|
122
|
+
CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
|
123
|
+
"SELECT * FROM foo WHERE fooid = #{args[0]}"
|
124
|
+
' language 'plruby';
|
125
|
+
SELECT * FROM getfoo(1) AS t1;
|
126
|
+
fooid | foosubid | fooname
|
127
|
+
-------+----------+---------
|
128
|
+
1 | 1 | Joe
|
129
|
+
1 | 2 | Ed
|
130
|
+
(2 rows)
|
131
|
+
|
132
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
133
|
+
SELECT * FROM vw_getfoo;
|
134
|
+
fooid | foosubid | fooname
|
135
|
+
-------+----------+---------
|
136
|
+
1 | 1 | Joe
|
137
|
+
1 | 2 | Ed
|
138
|
+
(2 rows)
|
139
|
+
|
140
|
+
DROP VIEW vw_getfoo;
|
141
|
+
DROP FUNCTION getfoo(int);
|
142
|
+
CREATE FUNCTION getfoo(int) RETURNS setof record AS '
|
143
|
+
"SELECT * FROM foo WHERE fooid = #{args[0]}"
|
144
|
+
' language 'plruby';
|
145
|
+
SELECT * FROM getfoo(1) AS t1(fooid int, foosubid int, fooname text);
|
146
|
+
fooid | foosubid | fooname
|
147
|
+
-------+----------+---------
|
148
|
+
1 | 1 | Joe
|
149
|
+
1 | 2 | Ed
|
150
|
+
(2 rows)
|
151
|
+
|
152
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1) AS (fooid int, foosubid int, fooname text);
|
153
|
+
SELECT * FROM vw_getfoo;
|
154
|
+
fooid | foosubid | fooname
|
155
|
+
-------+----------+---------
|
156
|
+
1 | 1 | Joe
|
157
|
+
1 | 2 | Ed
|
158
|
+
(2 rows)
|
159
|
+
|
160
|
+
DROP VIEW vw_getfoo;
|
161
|
+
DROP FUNCTION getfoo(int);
|
162
|
+
CREATE FUNCTION getfoo(int) RETURNS setof int AS '
|
163
|
+
PL.exec("SELECT fooid FROM foo WHERE fooid = #{args[0]}") do |row|
|
164
|
+
yield row.values
|
165
|
+
end
|
166
|
+
' language 'plruby';
|
167
|
+
SELECT * FROM getfoo(1) AS t1;
|
168
|
+
t1
|
169
|
+
----
|
170
|
+
1
|
171
|
+
1
|
172
|
+
(2 rows)
|
173
|
+
|
174
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
175
|
+
SELECT * FROM vw_getfoo;
|
176
|
+
getfoo
|
177
|
+
--------
|
178
|
+
1
|
179
|
+
1
|
180
|
+
(2 rows)
|
181
|
+
|
182
|
+
DROP VIEW vw_getfoo;
|
183
|
+
DROP FUNCTION getfoo(int);
|
184
|
+
CREATE FUNCTION getfoo(int) RETURNS setof foo AS '
|
185
|
+
PL.exec("SELECT * FROM foo WHERE fooid = #{args[0]}", nil, "value") do |r|
|
186
|
+
yield r
|
187
|
+
end
|
188
|
+
' language 'plruby';
|
189
|
+
SELECT * FROM getfoo(1) AS t1;
|
190
|
+
fooid | foosubid | fooname
|
191
|
+
-------+----------+---------
|
192
|
+
1 | 1 | Joe
|
193
|
+
1 | 2 | Ed
|
194
|
+
(2 rows)
|
195
|
+
|
196
|
+
CREATE VIEW vw_getfoo AS SELECT * FROM getfoo(1);
|
197
|
+
SELECT * FROM vw_getfoo;
|
198
|
+
fooid | foosubid | fooname
|
199
|
+
-------+----------+---------
|
200
|
+
1 | 1 | Joe
|
201
|
+
1 | 2 | Ed
|
202
|
+
(2 rows)
|
203
|
+
|
204
|
+
DROP VIEW vw_getfoo;
|
205
|
+
DROP FUNCTION getfoo(int);
|
206
|
+
DROP FUNCTION foot(int);
|
207
|
+
DROP TABLE foo2;
|
208
|
+
DROP TABLE foo;
|
209
|
+
CREATE TABLE foorescan (fooid int, foosubid int, fooname text, primary key(fooid,foosubid));
|
210
|
+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foorescan_pkey" for table "foorescan"
|
211
|
+
INSERT INTO foorescan values(5000,1,'abc.5000.1');
|
212
|
+
INSERT INTO foorescan values(5001,1,'abc.5001.1');
|
213
|
+
INSERT INTO foorescan values(5002,1,'abc.5002.1');
|
214
|
+
INSERT INTO foorescan values(5003,1,'abc.5003.1');
|
215
|
+
INSERT INTO foorescan values(5004,1,'abc.5004.1');
|
216
|
+
INSERT INTO foorescan values(5005,1,'abc.5005.1');
|
217
|
+
INSERT INTO foorescan values(5006,1,'abc.5006.1');
|
218
|
+
INSERT INTO foorescan values(5007,1,'abc.5007.1');
|
219
|
+
INSERT INTO foorescan values(5008,1,'abc.5008.1');
|
220
|
+
INSERT INTO foorescan values(5009,1,'abc.5009.1');
|
221
|
+
INSERT INTO foorescan values(5000,2,'abc.5000.2');
|
222
|
+
INSERT INTO foorescan values(5001,2,'abc.5001.2');
|
223
|
+
INSERT INTO foorescan values(5002,2,'abc.5002.2');
|
224
|
+
INSERT INTO foorescan values(5003,2,'abc.5003.2');
|
225
|
+
INSERT INTO foorescan values(5004,2,'abc.5004.2');
|
226
|
+
INSERT INTO foorescan values(5005,2,'abc.5005.2');
|
227
|
+
INSERT INTO foorescan values(5006,2,'abc.5006.2');
|
228
|
+
INSERT INTO foorescan values(5007,2,'abc.5007.2');
|
229
|
+
INSERT INTO foorescan values(5008,2,'abc.5008.2');
|
230
|
+
INSERT INTO foorescan values(5009,2,'abc.5009.2');
|
231
|
+
INSERT INTO foorescan values(5000,3,'abc.5000.3');
|
232
|
+
INSERT INTO foorescan values(5001,3,'abc.5001.3');
|
233
|
+
INSERT INTO foorescan values(5002,3,'abc.5002.3');
|
234
|
+
INSERT INTO foorescan values(5003,3,'abc.5003.3');
|
235
|
+
INSERT INTO foorescan values(5004,3,'abc.5004.3');
|
236
|
+
INSERT INTO foorescan values(5005,3,'abc.5005.3');
|
237
|
+
INSERT INTO foorescan values(5006,3,'abc.5006.3');
|
238
|
+
INSERT INTO foorescan values(5007,3,'abc.5007.3');
|
239
|
+
INSERT INTO foorescan values(5008,3,'abc.5008.3');
|
240
|
+
INSERT INTO foorescan values(5009,3,'abc.5009.3');
|
241
|
+
INSERT INTO foorescan values(5000,4,'abc.5000.4');
|
242
|
+
INSERT INTO foorescan values(5001,4,'abc.5001.4');
|
243
|
+
INSERT INTO foorescan values(5002,4,'abc.5002.4');
|
244
|
+
INSERT INTO foorescan values(5003,4,'abc.5003.4');
|
245
|
+
INSERT INTO foorescan values(5004,4,'abc.5004.4');
|
246
|
+
INSERT INTO foorescan values(5005,4,'abc.5005.4');
|
247
|
+
INSERT INTO foorescan values(5006,4,'abc.5006.4');
|
248
|
+
INSERT INTO foorescan values(5007,4,'abc.5007.4');
|
249
|
+
INSERT INTO foorescan values(5008,4,'abc.5008.4');
|
250
|
+
INSERT INTO foorescan values(5009,4,'abc.5009.4');
|
251
|
+
INSERT INTO foorescan values(5000,5,'abc.5000.5');
|
252
|
+
INSERT INTO foorescan values(5001,5,'abc.5001.5');
|
253
|
+
INSERT INTO foorescan values(5002,5,'abc.5002.5');
|
254
|
+
INSERT INTO foorescan values(5003,5,'abc.5003.5');
|
255
|
+
INSERT INTO foorescan values(5004,5,'abc.5004.5');
|
256
|
+
INSERT INTO foorescan values(5005,5,'abc.5005.5');
|
257
|
+
INSERT INTO foorescan values(5006,5,'abc.5006.5');
|
258
|
+
INSERT INTO foorescan values(5007,5,'abc.5007.5');
|
259
|
+
INSERT INTO foorescan values(5008,5,'abc.5008.5');
|
260
|
+
INSERT INTO foorescan values(5009,5,'abc.5009.5');
|
261
|
+
CREATE FUNCTION foorescan(int,int) RETURNS setof foorescan AS '
|
262
|
+
"SELECT * FROM foorescan WHERE fooid >= #{args[0]} and fooid < #{args[1]}"
|
263
|
+
' language 'plruby';
|
264
|
+
SELECT * FROM foorescan f WHERE f.fooid IN (
|
265
|
+
SELECT fooid FROM foorescan(5002,5004)
|
266
|
+
) ORDER BY 1,2;
|
267
|
+
fooid | foosubid | fooname
|
268
|
+
-------+----------+------------
|
269
|
+
5002 | 1 | abc.5002.1
|
270
|
+
5002 | 2 | abc.5002.2
|
271
|
+
5002 | 3 | abc.5002.3
|
272
|
+
5002 | 4 | abc.5002.4
|
273
|
+
5002 | 5 | abc.5002.5
|
274
|
+
5003 | 1 | abc.5003.1
|
275
|
+
5003 | 2 | abc.5003.2
|
276
|
+
5003 | 3 | abc.5003.3
|
277
|
+
5003 | 4 | abc.5003.4
|
278
|
+
5003 | 5 | abc.5003.5
|
279
|
+
(10 rows)
|
280
|
+
|
281
|
+
CREATE VIEW vw_foorescan AS SELECT * FROM foorescan(5002,5004);
|
282
|
+
SELECT * FROM foorescan f WHERE f.fooid IN (
|
283
|
+
SELECT fooid FROM vw_foorescan
|
284
|
+
) ORDER BY 1,2;
|
285
|
+
fooid | foosubid | fooname
|
286
|
+
-------+----------+------------
|
287
|
+
5002 | 1 | abc.5002.1
|
288
|
+
5002 | 2 | abc.5002.2
|
289
|
+
5002 | 3 | abc.5002.3
|
290
|
+
5002 | 4 | abc.5002.4
|
291
|
+
5002 | 5 | abc.5002.5
|
292
|
+
5003 | 1 | abc.5003.1
|
293
|
+
5003 | 2 | abc.5003.2
|
294
|
+
5003 | 3 | abc.5003.3
|
295
|
+
5003 | 4 | abc.5003.4
|
296
|
+
5003 | 5 | abc.5003.5
|
297
|
+
(10 rows)
|
298
|
+
|
299
|
+
CREATE TABLE barrescan (fooid int primary key);
|
300
|
+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "barrescan_pkey" for table "barrescan"
|
301
|
+
INSERT INTO barrescan values(5003);
|
302
|
+
INSERT INTO barrescan values(5004);
|
303
|
+
INSERT INTO barrescan values(5005);
|
304
|
+
INSERT INTO barrescan values(5006);
|
305
|
+
INSERT INTO barrescan values(5007);
|
306
|
+
INSERT INTO barrescan values(5008);
|
307
|
+
CREATE FUNCTION foorescan(int) RETURNS setof foorescan AS '
|
308
|
+
"SELECT * FROM foorescan WHERE fooid = #{args[0]}"
|
309
|
+
' language 'plruby';
|
310
|
+
SELECT f.* FROM barrescan b, foorescan f
|
311
|
+
WHERE f.fooid = b.fooid AND b.fooid IN (
|
312
|
+
SELECT fooid FROM foorescan(b.fooid)
|
313
|
+
) ORDER BY 1,2;
|
314
|
+
fooid | foosubid | fooname
|
315
|
+
-------+----------+------------
|
316
|
+
5003 | 1 | abc.5003.1
|
317
|
+
5003 | 2 | abc.5003.2
|
318
|
+
5003 | 3 | abc.5003.3
|
319
|
+
5003 | 4 | abc.5003.4
|
320
|
+
5003 | 5 | abc.5003.5
|
321
|
+
5004 | 1 | abc.5004.1
|
322
|
+
5004 | 2 | abc.5004.2
|
323
|
+
5004 | 3 | abc.5004.3
|
324
|
+
5004 | 4 | abc.5004.4
|
325
|
+
5004 | 5 | abc.5004.5
|
326
|
+
5005 | 1 | abc.5005.1
|
327
|
+
5005 | 2 | abc.5005.2
|
328
|
+
5005 | 3 | abc.5005.3
|
329
|
+
5005 | 4 | abc.5005.4
|
330
|
+
5005 | 5 | abc.5005.5
|
331
|
+
5006 | 1 | abc.5006.1
|
332
|
+
5006 | 2 | abc.5006.2
|
333
|
+
5006 | 3 | abc.5006.3
|
334
|
+
5006 | 4 | abc.5006.4
|
335
|
+
5006 | 5 | abc.5006.5
|
336
|
+
5007 | 1 | abc.5007.1
|
337
|
+
5007 | 2 | abc.5007.2
|
338
|
+
5007 | 3 | abc.5007.3
|
339
|
+
5007 | 4 | abc.5007.4
|
340
|
+
5007 | 5 | abc.5007.5
|
341
|
+
5008 | 1 | abc.5008.1
|
342
|
+
5008 | 2 | abc.5008.2
|
343
|
+
5008 | 3 | abc.5008.3
|
344
|
+
5008 | 4 | abc.5008.4
|
345
|
+
5008 | 5 | abc.5008.5
|
346
|
+
(30 rows)
|
347
|
+
|
348
|
+
SELECT b.fooid, max(f.foosubid) FROM barrescan b, foorescan f
|
349
|
+
WHERE f.fooid = b.fooid AND b.fooid IN (
|
350
|
+
SELECT fooid FROM foorescan(b.fooid)
|
351
|
+
) GROUP BY b.fooid ORDER BY 1,2;
|
352
|
+
fooid | max
|
353
|
+
-------+-----
|
354
|
+
5003 | 5
|
355
|
+
5004 | 5
|
356
|
+
5005 | 5
|
357
|
+
5006 | 5
|
358
|
+
5007 | 5
|
359
|
+
5008 | 5
|
360
|
+
(6 rows)
|
361
|
+
|
362
|
+
CREATE VIEW fooview1 AS SELECT f.* FROM barrescan b, foorescan f
|
363
|
+
WHERE f.fooid = b.fooid AND b.fooid IN (
|
364
|
+
SELECT fooid FROM foorescan(b.fooid)
|
365
|
+
) ORDER BY 1,2;
|
366
|
+
SELECT * FROM fooview1 AS fv WHERE fv.fooid = 5004;
|
367
|
+
fooid | foosubid | fooname
|
368
|
+
-------+----------+------------
|
369
|
+
5004 | 1 | abc.5004.1
|
370
|
+
5004 | 2 | abc.5004.2
|
371
|
+
5004 | 3 | abc.5004.3
|
372
|
+
5004 | 4 | abc.5004.4
|
373
|
+
5004 | 5 | abc.5004.5
|
374
|
+
(5 rows)
|
375
|
+
|
376
|
+
CREATE VIEW fooview2 AS SELECT b.fooid, max(f.foosubid) AS maxsubid
|
377
|
+
FROM barrescan b, foorescan f WHERE f.fooid = b.fooid AND b.fooid IN (
|
378
|
+
SELECT fooid FROM foorescan(b.fooid)
|
379
|
+
) GROUP BY b.fooid ORDER BY 1,2;
|
380
|
+
SELECT * FROM fooview2 AS fv WHERE fv.maxsubid = 5;
|
381
|
+
fooid | maxsubid
|
382
|
+
-------+----------
|
383
|
+
5003 | 5
|
384
|
+
5004 | 5
|
385
|
+
5005 | 5
|
386
|
+
5006 | 5
|
387
|
+
5007 | 5
|
388
|
+
5008 | 5
|
389
|
+
(6 rows)
|
390
|
+
|
391
|
+
DROP VIEW vw_foorescan;
|
392
|
+
DROP VIEW fooview1;
|
393
|
+
DROP VIEW fooview2;
|
394
|
+
DROP FUNCTION foorescan(int,int);
|
395
|
+
DROP FUNCTION foorescan(int);
|
396
|
+
DROP TABLE foorescan;
|
397
|
+
DROP TABLE barrescan;
|