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,194 @@
1
+ set client_min_messages = 'WARNING';
2
+
3
+ create table pl_box (
4
+ data box, barea float, boverlaps bool, boverleft bool, boverright bool,
5
+ bleft bool, bright bool
6
+ );
7
+
8
+ create or replace function box_val(box[]) returns setof pl_box as '
9
+ b1 = Box.new(2.5,2.5,1.0,1.0)
10
+ b2 = Box.new(2.0,2.0,2.5,2.5)
11
+ b3 = Box.new(3.0,3.0,5.0,5.0)
12
+ args[0].each do |b|
13
+ yield [b, b.area, b.overlap?(b1), b.overleft?(b2),
14
+ b.overright?(b2), b.left?(b3), b3.right?(b)]
15
+ end
16
+ ' language 'plruby';
17
+
18
+ select * from
19
+ 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[]);
20
+
21
+ drop table pl_box cascade;
22
+
23
+ create table pl_box (
24
+ b box, bcmp1 int, bcmp2 int, bin bool, bcontain bool, bcenter point
25
+ );
26
+
27
+ create or replace function box_val(box[]) returns setof pl_box as '
28
+ b1 = Box.new(3.0,3.0,5.0,5.0)
29
+ b2 = Box.new(3.5,3.0,4.5,3.0)
30
+ b3 = Box.new(0,0,3,3)
31
+ args[0].each do |b|
32
+ yield [b, b <=> b1, b <=> b2, b.in?(b3), b.contain?(b3), b.center]
33
+ end
34
+ ' language 'plruby';
35
+
36
+ select * from
37
+ 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[]);
38
+
39
+ drop table pl_box cascade;
40
+
41
+ create table pl_box (
42
+ b0 box, b1 box, b2 box, b3 box
43
+ );
44
+
45
+ create or replace function box_val(box[]) returns setof pl_box as '
46
+ p0 = [Point.new(-10.0,0.0), Point.new(-3.0,4.0),
47
+ Point.new(5.1, 34.5), Point.new(-5.0,-12.0)]
48
+ args[0].each do |b|
49
+ p0.each do |p|
50
+ yield [b + p, b - p, b * p, b / p]
51
+ end
52
+ p0.each do |p|
53
+ yield [p + b, p - b, p * b, p / b]
54
+ end
55
+ end
56
+ ' language 'plruby';
57
+
58
+ select * from
59
+ 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[]);
60
+
61
+ drop table pl_box cascade;
62
+
63
+ create table pl_box (
64
+ p point, dp float, d0 float, c circle, w float, h float
65
+ );
66
+
67
+ create or replace function box_val(box[]) returns setof pl_box as '
68
+ p = Point.new(6,4)
69
+ args[0].each do |b|
70
+ p0 = b.center
71
+ yield [p0, Geometry::distance(p, b),Geometry::distance(p, p0),
72
+ b.to_circle, b.height, b.width]
73
+ end
74
+ ' language 'plruby';
75
+
76
+ select * from
77
+ 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[]);
78
+
79
+ drop table pl_box cascade;
80
+
81
+ create table pl_box (
82
+ nb int, ll float, pc bool
83
+ );
84
+
85
+ create or replace function path_val(path[]) returns setof pl_box as '
86
+ args[0].each do |b|
87
+ yield [b.npoints, b.length, b.closed?]
88
+ end
89
+ ' language 'plruby';
90
+
91
+ select * from
92
+ path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
93
+
94
+ drop table pl_box cascade;
95
+
96
+ create table pl_box (
97
+ p path, p0 path, p1 path
98
+ );
99
+
100
+ create or replace function path_val(path[]) returns setof pl_box as '
101
+ p0 = Point.new(6,7)
102
+ args[0].each do |b|
103
+ yield [b, b + p0, b - p0]
104
+ end
105
+ ' language 'plruby';
106
+
107
+ select * from
108
+ path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
109
+
110
+ drop table pl_box cascade;
111
+
112
+ create table pl_box (
113
+ p path, p0 path, p1 path
114
+ );
115
+
116
+ create or replace function path_val(path[]) returns setof pl_box as '
117
+ p0 = Point.new(6,7)
118
+ args[0].each do |b|
119
+ yield [b, b * p0, b / p0]
120
+ end
121
+ ' language 'plruby';
122
+
123
+ select * from
124
+ path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
125
+
126
+ drop table pl_box cascade;
127
+
128
+ create table pl_box (
129
+ center point, area float, radius float, diameter float
130
+ );
131
+
132
+ create or replace function circle_val(circle[]) returns setof pl_box as '
133
+ args[0].each do |b|
134
+ yield b.center, b.area, b.radius, b.diameter
135
+ end
136
+ ' language 'plruby';
137
+
138
+ select * from
139
+ circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
140
+
141
+
142
+ drop table pl_box cascade;
143
+
144
+ create table pl_box (
145
+ p circle, p0 circle, p1 circle
146
+ );
147
+
148
+ create or replace function circle_val(circle[]) returns setof pl_box as '
149
+ p0 = Point.new(6,7)
150
+ args[0].each do |b|
151
+ yield [b, b + p0, b - p0]
152
+ end
153
+ ' language 'plruby';
154
+
155
+ select * from
156
+ circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
157
+
158
+ drop table pl_box cascade;
159
+
160
+ create table pl_box (
161
+ p circle, p0 circle, p1 circle
162
+ );
163
+
164
+ create or replace function circle_val(circle[]) returns setof pl_box as '
165
+ p0 = Point.new(6,7)
166
+ args[0].each do |b|
167
+ yield [b, p0 * b, p0 / b ]
168
+ end
169
+ ' language 'plruby';
170
+
171
+ select * from
172
+ circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
173
+
174
+ drop table pl_box cascade;
175
+
176
+ create table pl_box (
177
+ overlap bool, overleft bool, overright bool,
178
+ bleft bool, bright bool, below bool, above bool
179
+ );
180
+
181
+ create or replace function circle_val(circle, circle) returns setof pl_box as '
182
+ b0 = args[0]
183
+ b1 = args[1]
184
+ yield b0.overlap?(b1), b0.overleft?(b1), b0.overright?(b1),
185
+ b0.left?(b1), b0.right?(b1), b0.below?(b1), b0.above?(b1)
186
+ ' language 'plruby';
187
+
188
+
189
+ select * from
190
+ circle_val('<(5,1),3>'::circle, '<(1,2),100>'::circle);
191
+
192
+ select * from
193
+ circle_val('<(100,200),10>'::circle, '<(100,1),115>'::circle);
194
+
@@ -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,213 @@
1
+ create table pl_inet (
2
+ host text, abbrev text, masklen int,
3
+ network inet, netmask inet, first inet, last inet
4
+ );
5
+ create or replace function inet_val(inet) returns pl_inet as '
6
+ a = args[0]
7
+ [a.host, a.abbrev, a.masklen, a.network, a.netmask,
8
+ a.first, a.last]
9
+ ' language 'plruby';
10
+ select * from inet_val('192.168.1'::cidr);
11
+ host | abbrev | masklen | network | netmask | first | last
12
+ -------------+--------------+---------+----------------+---------------+----------------+---------------
13
+ 192.168.1.0 | 192.168.1/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
14
+ (1 row)
15
+
16
+ select * from inet_val('192.168.1.226/24'::inet);
17
+ host | abbrev | masklen | network | netmask | first | last
18
+ ---------------+------------------+---------+----------------+---------------+----------------+---------------
19
+ 192.168.1.226 | 192.168.1.226/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
20
+ (1 row)
21
+
22
+ select * from inet_val('192.168.1.0/24'::cidr);
23
+ host | abbrev | masklen | network | netmask | first | last
24
+ -------------+--------------+---------+----------------+---------------+----------------+---------------
25
+ 192.168.1.0 | 192.168.1/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
26
+ (1 row)
27
+
28
+ select * from inet_val('192.168.1.226'::inet);
29
+ host | abbrev | masklen | network | netmask | first | last
30
+ ---------------+---------------+---------+------------------+-----------------+------------------+---------------
31
+ 192.168.1.226 | 192.168.1.226 | 32 | 192.168.1.226/32 | 255.255.255.255 | 192.168.1.226/32 | 192.168.1.226
32
+ (1 row)
33
+
34
+ select * from inet_val('192.168.1'::cidr);
35
+ host | abbrev | masklen | network | netmask | first | last
36
+ -------------+--------------+---------+----------------+---------------+----------------+---------------
37
+ 192.168.1.0 | 192.168.1/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
38
+ (1 row)
39
+
40
+ select * from inet_val('192.168.1.0/24'::inet);
41
+ host | abbrev | masklen | network | netmask | first | last
42
+ -------------+----------------+---------+----------------+---------------+----------------+---------------
43
+ 192.168.1.0 | 192.168.1.0/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
44
+ (1 row)
45
+
46
+ select * from inet_val('192.168.1'::cidr);
47
+ host | abbrev | masklen | network | netmask | first | last
48
+ -------------+--------------+---------+----------------+---------------+----------------+---------------
49
+ 192.168.1.0 | 192.168.1/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
50
+ (1 row)
51
+
52
+ select * from inet_val('192.168.1.0/25'::inet);
53
+ host | abbrev | masklen | network | netmask | first | last
54
+ -------------+----------------+---------+----------------+-----------------+----------------+---------------
55
+ 192.168.1.0 | 192.168.1.0/25 | 25 | 192.168.1.0/25 | 255.255.255.128 | 192.168.1.0/25 | 192.168.1.127
56
+ (1 row)
57
+
58
+ select * from inet_val('192.168.1'::cidr);
59
+ host | abbrev | masklen | network | netmask | first | last
60
+ -------------+--------------+---------+----------------+---------------+----------------+---------------
61
+ 192.168.1.0 | 192.168.1/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
62
+ (1 row)
63
+
64
+ select * from inet_val('192.168.1.255/24'::inet);
65
+ host | abbrev | masklen | network | netmask | first | last
66
+ ---------------+------------------+---------+----------------+---------------+----------------+---------------
67
+ 192.168.1.255 | 192.168.1.255/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
68
+ (1 row)
69
+
70
+ select * from inet_val('192.168.1'::cidr);
71
+ host | abbrev | masklen | network | netmask | first | last
72
+ -------------+--------------+---------+----------------+---------------+----------------+---------------
73
+ 192.168.1.0 | 192.168.1/24 | 24 | 192.168.1.0/24 | 255.255.255.0 | 192.168.1.0/24 | 192.168.1.255
74
+ (1 row)
75
+
76
+ select * from inet_val('192.168.1.255/25'::inet);
77
+ host | abbrev | masklen | network | netmask | first | last
78
+ ---------------+------------------+---------+------------------+-----------------+------------------+---------------
79
+ 192.168.1.255 | 192.168.1.255/25 | 25 | 192.168.1.128/25 | 255.255.255.128 | 192.168.1.128/25 | 192.168.1.255
80
+ (1 row)
81
+
82
+ select * from inet_val('10'::cidr);
83
+ host | abbrev | masklen | network | netmask | first | last
84
+ ----------+--------+---------+------------+-----------+------------+----------------
85
+ 10.0.0.0 | 10/8 | 8 | 10.0.0.0/8 | 255.0.0.0 | 10.0.0.0/8 | 10.255.255.255
86
+ (1 row)
87
+
88
+ select * from inet_val('10.1.2.3/8'::inet);
89
+ host | abbrev | masklen | network | netmask | first | last
90
+ ----------+------------+---------+------------+-----------+------------+----------------
91
+ 10.1.2.3 | 10.1.2.3/8 | 8 | 10.0.0.0/8 | 255.0.0.0 | 10.0.0.0/8 | 10.255.255.255
92
+ (1 row)
93
+
94
+ select * from inet_val('10.0.0.0'::cidr);
95
+ host | abbrev | masklen | network | netmask | first | last
96
+ ----------+-------------+---------+-------------+-----------------+-------------+----------
97
+ 10.0.0.0 | 10.0.0.0/32 | 32 | 10.0.0.0/32 | 255.255.255.255 | 10.0.0.0/32 | 10.0.0.0
98
+ (1 row)
99
+
100
+ select * from inet_val('10.1.2.3/8'::inet);
101
+ host | abbrev | masklen | network | netmask | first | last
102
+ ----------+------------+---------+------------+-----------+------------+----------------
103
+ 10.1.2.3 | 10.1.2.3/8 | 8 | 10.0.0.0/8 | 255.0.0.0 | 10.0.0.0/8 | 10.255.255.255
104
+ (1 row)
105
+
106
+ select * from inet_val('10.1.2.3'::cidr);
107
+ host | abbrev | masklen | network | netmask | first | last
108
+ ----------+-------------+---------+-------------+-----------------+-------------+----------
109
+ 10.1.2.3 | 10.1.2.3/32 | 32 | 10.1.2.3/32 | 255.255.255.255 | 10.1.2.3/32 | 10.1.2.3
110
+ (1 row)
111
+
112
+ select * from inet_val('10.1.2.3/32'::inet);
113
+ host | abbrev | masklen | network | netmask | first | last
114
+ ----------+----------+---------+-------------+-----------------+-------------+----------
115
+ 10.1.2.3 | 10.1.2.3 | 32 | 10.1.2.3/32 | 255.255.255.255 | 10.1.2.3/32 | 10.1.2.3
116
+ (1 row)
117
+
118
+ select * from inet_val('10.1.2'::cidr);
119
+ host | abbrev | masklen | network | netmask | first | last
120
+ ----------+-----------+---------+-------------+---------------+-------------+------------
121
+ 10.1.2.0 | 10.1.2/24 | 24 | 10.1.2.0/24 | 255.255.255.0 | 10.1.2.0/24 | 10.1.2.255
122
+ (1 row)
123
+
124
+ select * from inet_val('10.1.2.3/24'::inet);
125
+ host | abbrev | masklen | network | netmask | first | last
126
+ ----------+-------------+---------+-------------+---------------+-------------+------------
127
+ 10.1.2.3 | 10.1.2.3/24 | 24 | 10.1.2.0/24 | 255.255.255.0 | 10.1.2.0/24 | 10.1.2.255
128
+ (1 row)
129
+
130
+ select * from inet_val('10.1'::cidr);
131
+ host | abbrev | masklen | network | netmask | first | last
132
+ ----------+---------+---------+-------------+-------------+-------------+--------------
133
+ 10.1.0.0 | 10.1/16 | 16 | 10.1.0.0/16 | 255.255.0.0 | 10.1.0.0/16 | 10.1.255.255
134
+ (1 row)
135
+
136
+ select * from inet_val('10.1.2.3/16'::inet);
137
+ host | abbrev | masklen | network | netmask | first | last
138
+ ----------+-------------+---------+-------------+-------------+-------------+--------------
139
+ 10.1.2.3 | 10.1.2.3/16 | 16 | 10.1.0.0/16 | 255.255.0.0 | 10.1.0.0/16 | 10.1.255.255
140
+ (1 row)
141
+
142
+ select * from inet_val('10'::cidr);
143
+ host | abbrev | masklen | network | netmask | first | last
144
+ ----------+--------+---------+------------+-----------+------------+----------------
145
+ 10.0.0.0 | 10/8 | 8 | 10.0.0.0/8 | 255.0.0.0 | 10.0.0.0/8 | 10.255.255.255
146
+ (1 row)
147
+
148
+ select * from inet_val('10.1.2.3/8'::inet);
149
+ host | abbrev | masklen | network | netmask | first | last
150
+ ----------+------------+---------+------------+-----------+------------+----------------
151
+ 10.1.2.3 | 10.1.2.3/8 | 8 | 10.0.0.0/8 | 255.0.0.0 | 10.0.0.0/8 | 10.255.255.255
152
+ (1 row)
153
+
154
+ select * from inet_val('10'::cidr);
155
+ host | abbrev | masklen | network | netmask | first | last
156
+ ----------+--------+---------+------------+-----------+------------+----------------
157
+ 10.0.0.0 | 10/8 | 8 | 10.0.0.0/8 | 255.0.0.0 | 10.0.0.0/8 | 10.255.255.255
158
+ (1 row)
159
+
160
+ select * from inet_val('11.1.2.3/8'::inet);
161
+ host | abbrev | masklen | network | netmask | first | last
162
+ ----------+------------+---------+------------+-----------+------------+----------------
163
+ 11.1.2.3 | 11.1.2.3/8 | 8 | 11.0.0.0/8 | 255.0.0.0 | 11.0.0.0/8 | 11.255.255.255
164
+ (1 row)
165
+
166
+ select * from inet_val('10'::cidr);
167
+ host | abbrev | masklen | network | netmask | first | last
168
+ ----------+--------+---------+------------+-----------+------------+----------------
169
+ 10.0.0.0 | 10/8 | 8 | 10.0.0.0/8 | 255.0.0.0 | 10.0.0.0/8 | 10.255.255.255
170
+ (1 row)
171
+
172
+ select * from inet_val('9.1.2.3/8'::inet);
173
+ host | abbrev | masklen | network | netmask | first | last
174
+ ---------+-----------+---------+-----------+-----------+-----------+---------------
175
+ 9.1.2.3 | 9.1.2.3/8 | 8 | 9.0.0.0/8 | 255.0.0.0 | 9.0.0.0/8 | 9.255.255.255
176
+ (1 row)
177
+
178
+ select * from inet_val('10:23::f1'::cidr);
179
+ ERROR: invalid CIDR value '10:23::f1'
180
+ select * from inet_val('10:23::f1/64'::inet);
181
+ ERROR: invalid INET value '10:23::f1/64'
182
+ select * from inet_val('10:23::8000/113'::cidr);
183
+ ERROR: invalid CIDR value '10:23::8000/113'
184
+ select * from inet_val('10:23::ffff'::inet);
185
+ ERROR: invalid INET value '10:23::ffff'
186
+ select * from inet_val('::ffff:1.2.3.4'::cidr);
187
+ ERROR: invalid CIDR value '::ffff:1.2.3.4'
188
+ select * from inet_val('::4.3.2.1/24'::inet);
189
+ ERROR: invalid INET value '::4.3.2.1/24'
190
+ create or replace function mac_cmp(macaddr, macaddr) returns int as '
191
+ args[0] <=> args[1]
192
+ ' language 'plruby';
193
+ select mac_cmp('00:07:E9:85:3E:C5'::macaddr, '00:E0:29:3E:E7:25'::macaddr);
194
+ mac_cmp
195
+ ---------
196
+ -1
197
+ (1 row)
198
+
199
+ create or replace function mac_trunc(macaddr) returns macaddr as '
200
+ args[0].truncate
201
+ ' language 'plruby';
202
+ select mac_trunc('00:07:E9:85:3E:C5'::macaddr);
203
+ mac_trunc
204
+ -------------------
205
+ 00:07:e9:00:00:00
206
+ (1 row)
207
+
208
+ select mac_trunc('00:E0:29:3E:E7:25'::macaddr);
209
+ mac_trunc
210
+ -------------------
211
+ 00:e0:29:00:00:00
212
+ (1 row)
213
+