globegit-postgresql-plruby 0.5.4

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