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,148 @@
1
+ create table bit_op (
2
+ b0 bit(8), b1 bit(8), band bit(8), bor bit(8),
3
+ bxor bit(8), bnot0 bit(8), bnot1 bit(8)
4
+ );
5
+ create function bt(integer, integer) returns bit_op as '
6
+ b0 = BitString.new(args[0], 8)
7
+ b1 = BitString.new(args[1], 8)
8
+ [b0, b1, b0 & b1, b0 | b1, b0 ^ b1, ~b0, ~b1]
9
+ ' language 'plruby';
10
+ select * from bt(12, 24);
11
+ b0 | b1 | band | bor | bxor | bnot0 | bnot1
12
+ ----------+----------+----------+----------+----------+----------+----------
13
+ 00001100 | 00011000 | 00001000 | 00011100 | 00010100 | 11110011 | 11100111
14
+ (1 row)
15
+
16
+ select * from bt(12, 32);
17
+ b0 | b1 | band | bor | bxor | bnot0 | bnot1
18
+ ----------+----------+----------+----------+----------+----------+----------
19
+ 00001100 | 00100000 | 00000000 | 00101100 | 00101100 | 11110011 | 11011111
20
+ (1 row)
21
+
22
+ select * from bt(15, 278);
23
+ b0 | b1 | band | bor | bxor | bnot0 | bnot1
24
+ ----------+----------+----------+----------+----------+----------+----------
25
+ 00001111 | 00010110 | 00000110 | 00011111 | 00011001 | 11110000 | 11101001
26
+ (1 row)
27
+
28
+ create function be(integer) returns setof integer as '
29
+ BitString.new(args[0], 8).each {|i| yield i}
30
+ ' language 'plruby';
31
+ select * from be(12);
32
+ be
33
+ ----
34
+ 0
35
+ 0
36
+ 0
37
+ 0
38
+ 1
39
+ 1
40
+ 0
41
+ 0
42
+ (8 rows)
43
+
44
+ select * from be(257);
45
+ be
46
+ ----
47
+ 0
48
+ 0
49
+ 0
50
+ 0
51
+ 0
52
+ 0
53
+ 0
54
+ 1
55
+ (8 rows)
56
+
57
+ create function bx(integer, integer) returns bit varying as '
58
+ BitString.new(*args)
59
+ ' language 'plruby';
60
+ select bx(12, 6);
61
+ bx
62
+ --------
63
+ 001100
64
+ (1 row)
65
+
66
+ select bx(12, 8);
67
+ bx
68
+ ----------
69
+ 00001100
70
+ (1 row)
71
+
72
+ create table bit_sht (
73
+ b0 bit(8), shft int, bl bit(8), br bit(8), bs text, bi integer,
74
+ sz integer, osz integer
75
+ );
76
+ create function bs(integer, integer) returns bit_sht as '
77
+ b0 = BitString.new(args[0], 8)
78
+ [b0, args[1], b0 << args[1], b0 >> args[1], b0.to_s, b0.to_i,
79
+ b0.size, b0.octet_size]
80
+ ' language 'plruby';
81
+ select * from bs(12, 2);
82
+ b0 | shft | bl | br | bs | bi | sz | osz
83
+ ----------+------+----------+----------+----------+----+----+-----
84
+ 00001100 | 2 | 00110000 | 00000011 | 00001100 | 12 | 8 | 1
85
+ (1 row)
86
+
87
+ select * from bs(277, -3);
88
+ b0 | shft | bl | br | bs | bi | sz | osz
89
+ ----------+------+----------+----------+----------+----+----+-----
90
+ 00010101 | -3 | 00000010 | 10101000 | 00010101 | 21 | 8 | 1
91
+ (1 row)
92
+
93
+ create function ext(text, integer) returns integer as '
94
+ b0 = BitString.new(args[0])
95
+ b0[args[1]]
96
+ ' language 'plruby';
97
+ select ext('011110', 0);
98
+ ext
99
+ -----
100
+ 0
101
+ (1 row)
102
+
103
+ select ext('011110', -1);
104
+ ext
105
+ -----
106
+ 0
107
+ (1 row)
108
+
109
+ select ext('011110', 1);
110
+ ext
111
+ -----
112
+ 1
113
+ (1 row)
114
+
115
+ select ext('011110', 4);
116
+ ext
117
+ -----
118
+ 1
119
+ (1 row)
120
+
121
+ create function ext2(text, integer, integer) returns bit varying(8) as '
122
+ b0 = BitString.new(args[0])
123
+ b0[args[1], args[2]]
124
+ ' language 'plruby';
125
+ select ext2('0111101', 0, 2);
126
+ ext2
127
+ ------
128
+ 01
129
+ (1 row)
130
+
131
+ select ext2('0111101', -1, 3);
132
+ ext2
133
+ ------
134
+ 1
135
+ (1 row)
136
+
137
+ select ext2('0111101', 1, 2);
138
+ ext2
139
+ ------
140
+ 11
141
+ (1 row)
142
+
143
+ select ext2('0111101', 4, 1);
144
+ ext2
145
+ ------
146
+ 1
147
+ (1 row)
148
+
@@ -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,63 @@
1
+ create table bit_op (
2
+ b0 bit(8), b1 bit(8), band bit(8), bor bit(8),
3
+ bxor bit(8), bnot0 bit(8), bnot1 bit(8)
4
+ );
5
+
6
+ create function bt(integer, integer) returns bit_op as '
7
+ b0 = BitString.new(args[0], 8)
8
+ b1 = BitString.new(args[1], 8)
9
+ [b0, b1, b0 & b1, b0 | b1, b0 ^ b1, ~b0, ~b1]
10
+ ' language 'plruby';
11
+
12
+ select * from bt(12, 24);
13
+ select * from bt(12, 32);
14
+ select * from bt(15, 278);
15
+
16
+
17
+ create function be(integer) returns setof integer as '
18
+ BitString.new(args[0], 8).each {|i| yield i}
19
+ ' language 'plruby';
20
+
21
+ select * from be(12);
22
+ select * from be(257);
23
+
24
+ create function bx(integer, integer) returns bit varying as '
25
+ BitString.new(*args)
26
+ ' language 'plruby';
27
+
28
+ select bx(12, 6);
29
+ select bx(12, 8);
30
+
31
+ create table bit_sht (
32
+ b0 bit(8), shft int, bl bit(8), br bit(8), bs text, bi integer,
33
+ sz integer, osz integer
34
+ );
35
+
36
+ create function bs(integer, integer) returns bit_sht as '
37
+ b0 = BitString.new(args[0], 8)
38
+ [b0, args[1], b0 << args[1], b0 >> args[1], b0.to_s, b0.to_i,
39
+ b0.size, b0.octet_size]
40
+ ' language 'plruby';
41
+
42
+ select * from bs(12, 2);
43
+ select * from bs(277, -3);
44
+
45
+ create function ext(text, integer) returns integer as '
46
+ b0 = BitString.new(args[0])
47
+ b0[args[1]]
48
+ ' language 'plruby';
49
+
50
+ select ext('011110', 0);
51
+ select ext('011110', -1);
52
+ select ext('011110', 1);
53
+ select ext('011110', 4);
54
+
55
+ create function ext2(text, integer, integer) returns bit varying(8) as '
56
+ b0 = BitString.new(args[0])
57
+ b0[args[1], args[2]]
58
+ ' language 'plruby';
59
+
60
+ select ext2('0111101', 0, 2);
61
+ select ext2('0111101', -1, 3);
62
+ select ext2('0111101', 1, 2);
63
+ select ext2('0111101', 4, 1);
@@ -0,0 +1,63 @@
1
+ create table bit_op (
2
+ b0 bit(8), b1 bit(8), band bit(8), bor bit(8),
3
+ bxor bit(8), bnot0 bit(8), bnot1 bit(8)
4
+ );
5
+
6
+ create function bt(integer, integer) returns bit_op as '
7
+ b0 = BitString.new(args[0], 8)
8
+ b1 = BitString.new(args[1], 8)
9
+ [b0, b1, b0 & b1, b0 | b1, b0 ^ b1, ~b0, ~b1]
10
+ ' language 'plruby';
11
+
12
+ select * from bt(12, 24);
13
+ select * from bt(12, 32);
14
+ select * from bt(15, 278);
15
+
16
+
17
+ create function be(integer) returns setof integer as '
18
+ BitString.new(args[0], 8).each {|i| yield i}
19
+ ' language 'plruby';
20
+
21
+ select * from be(12);
22
+ select * from be(257);
23
+
24
+ create function bx(integer, integer) returns bit varying as '
25
+ BitString.new(*args)
26
+ ' language 'plruby';
27
+
28
+ select bx(12, 6);
29
+ select bx(12, 8);
30
+
31
+ create table bit_sht (
32
+ b0 bit(8), shft int, bl bit(8), br bit(8), bs text, bi integer,
33
+ sz integer, osz integer
34
+ );
35
+
36
+ create function bs(integer, integer) returns bit_sht as '
37
+ b0 = BitString.new(args[0], 8)
38
+ [b0, args[1], b0 << args[1], b0 >> args[1], b0.to_s, b0.to_i,
39
+ b0.size, b0.octet_size]
40
+ ' language 'plruby';
41
+
42
+ select * from bs(12, 2);
43
+ select * from bs(277, -3);
44
+
45
+ create function ext(text, integer) returns integer as '
46
+ b0 = BitString.new(args[0])
47
+ b0[args[1]]
48
+ ' language 'plruby';
49
+
50
+ select ext('011110', 0);
51
+ select ext('011110', -1);
52
+ select ext('011110', 1);
53
+ select ext('011110', 4);
54
+
55
+ create function ext2(text, integer, integer) returns bit varying(8) as '
56
+ b0 = BitString.new(args[0])
57
+ b0[args[1], args[2]]
58
+ ' language 'plruby';
59
+
60
+ select ext2('0111101', 0, 2);
61
+ select ext2('0111101', -1, 3);
62
+ select ext2('0111101', 1, 2);
63
+ select ext2('0111101', 4, 1);
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/ruby
2
+ require 'rbconfig'
3
+ include Config
4
+ pwd = Dir.pwd
5
+ pwd.sub!(%r{[^/]+/[^/]+$}, "")
6
+
7
+ language, extension = 'C', '_new_trigger'
8
+ opaque = 'language_handler'
9
+
10
+ version = ARGV[0].to_i
11
+ suffix = ARGV[1].to_s
12
+
13
+ begin
14
+ f = File.new("test_queries.sql", "w")
15
+ IO.foreach("test_queries.sql.in") do |x|
16
+ x.gsub!(/language\s+'plruby'/i, "language 'plruby#{suffix}'")
17
+ f.print x
18
+ end
19
+ f.close
20
+
21
+ Dir["test.expected.*.in"].each do |name|
22
+ result = name.sub(/\.in\z/, '')
23
+ f = File.new(result, "w")
24
+ IO.foreach(name) do |x|
25
+ x.gsub!(/'plruby'/i, "'plruby#{suffix}'")
26
+ f.print x
27
+ end
28
+ f.close
29
+ end
30
+
31
+ f = File.new("test_mklang.sql", "w")
32
+ f.print <<EOF
33
+
34
+ create function plruby#{suffix}_call_handler() returns #{opaque}
35
+ as '#{pwd}src/plruby#{suffix}.#{CONFIG["DLEXT"]}'
36
+ language '#{language}';
37
+
38
+ create trusted procedural language 'plruby#{suffix}'
39
+ handler plruby#{suffix}_call_handler
40
+ lancompiler 'PL/Ruby';
41
+ EOF
42
+ f.close
43
+ rescue
44
+ raise "Why I can't write #$!"
45
+ end
@@ -0,0 +1,26 @@
1
+ #!/bin/sh
2
+
3
+ DBNAME=plruby_test
4
+ export DBNAME
5
+
6
+ sleep 1
7
+ echo "**** Destroy old database $DBNAME ****"
8
+ dropdb $DBNAME
9
+
10
+ echo "**** Create test database $DBNAME ****"
11
+ createdb $DBNAME
12
+
13
+ echo "**** Create procedural language plruby$2 ****"
14
+ "${RUBY-ruby}" b.rb $*
15
+ psql -q -n -X $DBNAME < test_mklang.sql
16
+
17
+ echo "**** Running test queries ****"
18
+ psql -q -n -X -e $DBNAME < test_queries.sql > test.out 2>&1
19
+
20
+ if cmp -s test.expected.$1 test.out; then
21
+ echo " Tests passed O.K."
22
+ else
23
+ echo " Tests failed - look at diffs between"
24
+ echo " test.expected.$1 and test.out"
25
+ fi
26
+
@@ -0,0 +1,265 @@
1
+ set client_min_messages = 'WARNING';
2
+ create table pl_box (
3
+ data box, barea float, boverlaps bool, boverleft bool, boverright bool,
4
+ bleft bool, bright bool
5
+ );
6
+ create or replace function box_val(box[]) returns setof pl_box as '
7
+ b1 = Box.new(2.5,2.5,1.0,1.0)
8
+ b2 = Box.new(2.0,2.0,2.5,2.5)
9
+ b3 = Box.new(3.0,3.0,5.0,5.0)
10
+ args[0].each do |b|
11
+ yield [b, b.area, b.overlap?(b1), b.overleft?(b2),
12
+ b.overright?(b2), b.left?(b3), b3.right?(b)]
13
+ end
14
+ ' language 'plruby';
15
+ select * from
16
+ box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
17
+ data | barea | boverlaps | boverleft | boverright | bleft | bright
18
+ ---------------------+-------+-----------+-----------+------------+-------+--------
19
+ (2,2),(0,0) | 4 | t | t | f | t | t
20
+ (3,3),(1,1) | 4 | t | f | f | f | f
21
+ (2.5,3.5),(2.5,2.5) | 0 | t | t | t | t | t
22
+ (3,3),(3,3) | 0 | f | f | t | f | f
23
+ (4 rows)
24
+
25
+ drop table pl_box cascade;
26
+ create table pl_box (
27
+ b box, bcmp1 int, bcmp2 int, bin bool, bcontain bool, bcenter point
28
+ );
29
+ create or replace function box_val(box[]) returns setof pl_box as '
30
+ b1 = Box.new(3.0,3.0,5.0,5.0)
31
+ b2 = Box.new(3.5,3.0,4.5,3.0)
32
+ b3 = Box.new(0,0,3,3)
33
+ args[0].each do |b|
34
+ yield [b, b <=> b1, b <=> b2, b.in?(b3), b.contain?(b3), b.center]
35
+ end
36
+ ' language 'plruby';
37
+ select * from
38
+ box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
39
+ b | bcmp1 | bcmp2 | bin | bcontain | bcenter
40
+ ---------------------+-------+-------+-----+----------+---------
41
+ (2,2),(0,0) | 0 | 1 | t | f | (1,1)
42
+ (3,3),(1,1) | 0 | 1 | t | f | (2,2)
43
+ (2.5,3.5),(2.5,2.5) | -1 | 0 | f | f | (2.5,3)
44
+ (3,3),(3,3) | -1 | 0 | t | f | (3,3)
45
+ (4 rows)
46
+
47
+ drop table pl_box cascade;
48
+ create table pl_box (
49
+ b0 box, b1 box, b2 box, b3 box
50
+ );
51
+ create or replace function box_val(box[]) returns setof pl_box as '
52
+ p0 = [Point.new(-10.0,0.0), Point.new(-3.0,4.0),
53
+ Point.new(5.1, 34.5), Point.new(-5.0,-12.0)]
54
+ args[0].each do |b|
55
+ p0.each do |p|
56
+ yield [b + p, b - p, b * p, b / p]
57
+ end
58
+ p0.each do |p|
59
+ yield [p + b, p - b, p * b, p / b]
60
+ end
61
+ end
62
+ ' language 'plruby';
63
+ select * from
64
+ box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
65
+ b0 | b1 | b2 | b3
66
+ -------------------------+---------------------------+-----------------------------+-----------------------------------------------------------------------------------
67
+ (-8,2),(-10,0) | (12,2),(10,0) | (-0,0),(-20,-20) | (0,-0),(-0.2,-0.2)
68
+ (-1,6),(-3,4) | (5,-2),(3,-4) | (-0,2),(-14,0) | (0.08,-0),(0,-0.56)
69
+ (7.1,36.5),(5.1,34.5) | (-3.1,-32.5),(-5.1,-34.5) | (0,79.2),(-58.8,0) | (0.0651176557643925,0),(0,-0.0483449262493217)
70
+ (-3,-10),(-5,-12) | (7,14),(5,12) | (14,-0),(0,-34) | (-0,0.0828402366863905),(-0.201183431952663,0)
71
+ (-8,2),(-10,0) | (12,2),(10,0) | (-0,0),(-20,-20) | (0,-0),(-0.2,-0.2)
72
+ (-1,6),(-3,4) | (5,-2),(3,-4) | (-0,2),(-14,0) | (0.08,-0),(0,-0.56)
73
+ (7.1,36.5),(5.1,34.5) | (-3.1,-32.5),(-5.1,-34.5) | (0,79.2),(-58.8,0) | (0.0651176557643925,0),(0,-0.0483449262493217)
74
+ (-3,-10),(-5,-12) | (7,14),(5,12) | (14,-0),(0,-34) | (-0,0.0828402366863905),(-0.201183431952663,0)
75
+ (-7,3),(-9,1) | (13,3),(11,1) | (-10,-10),(-30,-30) | (-0.1,-0.1),(-0.3,-0.3)
76
+ (0,7),(-2,5) | (6,-1),(4,-3) | (-7,3),(-21,1) | (0.12,-0.28),(0.04,-0.84)
77
+ (8.1,37.5),(6.1,35.5) | (-2.1,-31.5),(-4.1,-33.5) | (-29.4,118.8),(-88.2,39.6) | (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
78
+ (-2,-9),(-4,-11) | (8,15),(6,13) | (21,-17),(7,-51) | (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
79
+ (-7,3),(-9,1) | (13,3),(11,1) | (-10,-10),(-30,-30) | (-0.1,-0.1),(-0.3,-0.3)
80
+ (0,7),(-2,5) | (6,-1),(4,-3) | (-7,3),(-21,1) | (0.12,-0.28),(0.04,-0.84)
81
+ (8.1,37.5),(6.1,35.5) | (-2.1,-31.5),(-4.1,-33.5) | (-29.4,118.8),(-88.2,39.6) | (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
82
+ (-2,-9),(-4,-11) | (8,15),(6,13) | (21,-17),(7,-51) | (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
83
+ (-7.5,3.5),(-7.5,2.5) | (12.5,3.5),(12.5,2.5) | (-25,-25),(-25,-35) | (-0.25,-0.25),(-0.25,-0.35)
84
+ (-0.5,7.5),(-0.5,6.5) | (5.5,-0.5),(5.5,-1.5) | (-17.5,2.5),(-21.5,-0.5) | (0.26,-0.7),(0.1,-0.82)
85
+ (7.6,38),(7.6,37) | (-2.6,-31),(-2.6,-32) | (-73.5,104.1),(-108,99) | (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
86
+ (-2.5,-8.5),(-2.5,-9.5) | (7.5,15.5),(7.5,14.5) | (29.5,-42.5),(17.5,-47.5) | (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
87
+ (-7.5,3.5),(-7.5,2.5) | (12.5,3.5),(12.5,2.5) | (-25,-25),(-25,-35) | (-0.25,-0.25),(-0.25,-0.35)
88
+ (-0.5,7.5),(-0.5,6.5) | (5.5,-0.5),(5.5,-1.5) | (-17.5,2.5),(-21.5,-0.5) | (0.26,-0.7),(0.1,-0.82)
89
+ (7.6,38),(7.6,37) | (-2.6,-31),(-2.6,-32) | (-73.5,104.1),(-108,99) | (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
90
+ (-2.5,-8.5),(-2.5,-9.5) | (7.5,15.5),(7.5,14.5) | (29.5,-42.5),(17.5,-47.5) | (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
91
+ (-7,3),(-7,3) | (13,3),(13,3) | (-30,-30),(-30,-30) | (-0.3,-0.3),(-0.3,-0.3)
92
+ (0,7),(0,7) | (6,-1),(6,-1) | (-21,3),(-21,3) | (0.12,-0.84),(0.12,-0.84)
93
+ (8.1,37.5),(8.1,37.5) | (-2.1,-31.5),(-2.1,-31.5) | (-88.2,118.8),(-88.2,118.8) | (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
94
+ (-2,-9),(-2,-9) | (8,15),(8,15) | (21,-51),(21,-51) | (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
95
+ (-7,3),(-7,3) | (13,3),(13,3) | (-30,-30),(-30,-30) | (-0.3,-0.3),(-0.3,-0.3)
96
+ (0,7),(0,7) | (6,-1),(6,-1) | (-21,3),(-21,3) | (0.12,-0.84),(0.12,-0.84)
97
+ (8.1,37.5),(8.1,37.5) | (-2.1,-31.5),(-2.1,-31.5) | (-88.2,118.8),(-88.2,118.8) | (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
98
+ (-2,-9),(-2,-9) | (8,15),(8,15) | (21,-51),(21,-51) | (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
99
+ (32 rows)
100
+
101
+ drop table pl_box cascade;
102
+ create table pl_box (
103
+ p point, dp float, d0 float, c circle, w float, h float
104
+ );
105
+ create or replace function box_val(box[]) returns setof pl_box as '
106
+ p = Point.new(6,4)
107
+ args[0].each do |b|
108
+ p0 = b.center
109
+ yield [p0, Geometry::distance(p, b),Geometry::distance(p, p0),
110
+ b.to_circle, b.height, b.width]
111
+ end
112
+ ' language 'plruby';
113
+ select * from
114
+ box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
115
+ p | dp | d0 | c | w | h
116
+ ---------+------------------+------------------+-------------------------+---+---
117
+ (1,1) | 4.47213595499958 | 5.8309518948453 | <(1,1),1.4142135623731> | 2 | 2
118
+ (2,2) | 3.16227766016838 | 4.47213595499958 | <(2,2),1.4142135623731> | 2 | 2
119
+ (2.5,3) | 3.53553390593274 | 3.64005494464026 | <(2.5,3),0.5> | 1 | 0
120
+ (3,3) | 3.16227766016838 | 3.16227766016838 | <(3,3),0> | 0 | 0
121
+ (4 rows)
122
+
123
+ drop table pl_box cascade;
124
+ create table pl_box (
125
+ nb int, ll float, pc bool
126
+ );
127
+ create or replace function path_val(path[]) returns setof pl_box as '
128
+ args[0].each do |b|
129
+ yield [b.npoints, b.length, b.closed?]
130
+ end
131
+ ' language 'plruby';
132
+ select * from
133
+ path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
134
+ nb | ll | pc
135
+ ----+------------------+----
136
+ 2 | 2.82842712474619 | f
137
+ 4 | 17.3440597040594 | t
138
+ 3 | 28.9939521853426 | t
139
+ (3 rows)
140
+
141
+ drop table pl_box cascade;
142
+ create table pl_box (
143
+ p path, p0 path, p1 path
144
+ );
145
+ create or replace function path_val(path[]) returns setof pl_box as '
146
+ p0 = Point.new(6,7)
147
+ args[0].each do |b|
148
+ yield [b, b + p0, b - p0]
149
+ end
150
+ ' language 'plruby';
151
+ select * from
152
+ path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
153
+ p | p0 | p1
154
+ ---------------------------+------------------------------+-----------------------------------
155
+ [(1,2),(3,4)] | [(7,9),(9,11)] | [(-5,-5),(-3,-3)]
156
+ ((0,0),(3,0),(4,5),(1,6)) | ((6,7),(9,7),(10,12),(7,13)) | ((-6,-7),(-3,-7),(-2,-2),(-5,-1))
157
+ ((11,12),(13,14),(25,12)) | ((17,19),(19,21),(31,19)) | ((5,5),(7,7),(19,5))
158
+ (3 rows)
159
+
160
+ drop table pl_box cascade;
161
+ create table pl_box (
162
+ p path, p0 path, p1 path
163
+ );
164
+ create or replace function path_val(path[]) returns setof pl_box as '
165
+ p0 = Point.new(6,7)
166
+ args[0].each do |b|
167
+ yield [b, b * p0, b / p0]
168
+ end
169
+ ' language 'plruby';
170
+ select * from
171
+ path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
172
+ p | p0 | p1
173
+ ---------------------------+-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------
174
+ [(1,2),(3,4)] | [(-8,19),(-10,45)] | [(0.235294117647059,0.0588235294117647),(0.541176470588235,0.0352941176470588)]
175
+ ((0,0),(3,0),(4,5),(1,6)) | ((0,0),(18,21),(-11,58),(-36,43)) | ((0,0),(0.211764705882353,-0.247058823529412),(0.694117647058824,0.0235294117647059),(0.564705882352941,0.341176470588235))
176
+ ((11,12),(13,14),(25,12)) | ((-18,149),(-20,175),(66,247)) | ((1.76470588235294,-0.0588235294117647),(2.07058823529412,-0.0823529411764706),(2.75294117647059,-1.21176470588235))
177
+ (3 rows)
178
+
179
+ drop table pl_box cascade;
180
+ create table pl_box (
181
+ center point, area float, radius float, diameter float
182
+ );
183
+ create or replace function circle_val(circle[]) returns setof pl_box as '
184
+ args[0].each do |b|
185
+ yield b.center, b.area, b.radius, b.diameter
186
+ end
187
+ ' language 'plruby';
188
+ select * from
189
+ circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
190
+ center | area | radius | diameter
191
+ -----------+----------------+--------+----------
192
+ (5,1) | 28.2743338824 | 3 | 6
193
+ (1,2) | 31415.926536 | 100 | 200
194
+ (100,200) | 314.15926536 | 10 | 20
195
+ (100,1) | 41547.56284386 | 115 | 230
196
+ (1,3) | 78.53981634 | 5 | 10
197
+ (5 rows)
198
+
199
+ drop table pl_box cascade;
200
+ create table pl_box (
201
+ p circle, p0 circle, p1 circle
202
+ );
203
+ create or replace function circle_val(circle[]) returns setof pl_box as '
204
+ p0 = Point.new(6,7)
205
+ args[0].each do |b|
206
+ yield [b, b + p0, b - p0]
207
+ end
208
+ ' language 'plruby';
209
+ select * from
210
+ circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
211
+ p | p0 | p1
212
+ ----------------+----------------+---------------
213
+ <(5,1),3> | <(11,8),3> | <(-1,-6),3>
214
+ <(1,2),100> | <(7,9),100> | <(-5,-5),100>
215
+ <(100,200),10> | <(106,207),10> | <(94,193),10>
216
+ <(100,1),115> | <(106,8),115> | <(94,-6),115>
217
+ <(1,3),5> | <(7,10),5> | <(-5,-4),5>
218
+ (5 rows)
219
+
220
+ drop table pl_box cascade;
221
+ create table pl_box (
222
+ p circle, p0 circle, p1 circle
223
+ );
224
+ create or replace function circle_val(circle[]) returns setof pl_box as '
225
+ p0 = Point.new(6,7)
226
+ args[0].each do |b|
227
+ yield [b, p0 * b, p0 / b ]
228
+ end
229
+ ' language 'plruby';
230
+ select * from
231
+ circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
232
+ p | p0 | p1
233
+ ----------------+--------------------------------+------------------------------------------------------------
234
+ <(5,1),3> | <(23,41),27.6586333718787> | <(0.435294117647059,-0.341176470588235),0.325395686727984>
235
+ <(1,2),100> | <(-8,19),921.954445729289> | <(0.235294117647059,0.0588235294117647),10.8465228909328>
236
+ <(100,200),10> | <(-800,1900),92.1954445729289> | <(23.5294117647059,5.88235294117647),1.08465228909328>
237
+ <(100,1),115> | <(593,706),1060.24761258868> | <(7.14117647058824,-8.16470588235294),12.4735013245727>
238
+ <(1,3),5> | <(-15,25),46.0977222864644> | <(0.317647058823529,0.129411764705882),0.54232614454664>
239
+ (5 rows)
240
+
241
+ drop table pl_box cascade;
242
+ create table pl_box (
243
+ overlap bool, overleft bool, overright bool,
244
+ bleft bool, bright bool, below bool, above bool
245
+ );
246
+ create or replace function circle_val(circle, circle) returns setof pl_box as '
247
+ b0 = args[0]
248
+ b1 = args[1]
249
+ yield b0.overlap?(b1), b0.overleft?(b1), b0.overright?(b1),
250
+ b0.left?(b1), b0.right?(b1), b0.below?(b1), b0.above?(b1)
251
+ ' language 'plruby';
252
+ select * from
253
+ circle_val('<(5,1),3>'::circle, '<(1,2),100>'::circle);
254
+ overlap | overleft | overright | bleft | bright | below | above
255
+ ---------+----------+-----------+-------+--------+-------+-------
256
+ t | t | t | f | f | f | f
257
+ (1 row)
258
+
259
+ select * from
260
+ circle_val('<(100,200),10>'::circle, '<(100,1),115>'::circle);
261
+ overlap | overleft | overright | bleft | bright | below | above
262
+ ---------+----------+-----------+-------+--------+-------+-------
263
+ f | t | t | f | f | f | t
264
+ (1 row)
265
+