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