Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6761a03

Browse files
committed
Add regression test for macaddr type. Enhance documentation about accepted
input formats.
1 parent0e4896d commit6761a03

File tree

5 files changed

+174
-13
lines changed

5 files changed

+174
-13
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.228 2008/09/11 15:27:30 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.229 2008/10/03 15:37:18 petere Exp $ -->
22

33
<chapter id="datatype">
44
<title id="datatype-title">Data Types</title>
@@ -3187,23 +3187,39 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
31873187
</indexterm>
31883188

31893189
<para>
3190-
The <type>macaddr</> type stores MAC addresses,i.e., Ethernet
3191-
card hardware addresses (although MAC addresses are used for
3192-
other purposes as well). Input is accepted invarious customary
3193-
formats, including
3190+
The <type>macaddr</> type stores MAC addresses,known for example
3191+
from Ethernetcard hardware addresses (although MAC addresses are
3192+
used forother purposes as well). Input is accepted inthe
3193+
following formats:
31943194

31953195
<simplelist>
3196+
<member><literal>'08:00:2b:01:02:03'</></member>
3197+
<member><literal>'08-00-2b-01-02-03'</></member>
31963198
<member><literal>'08002b:010203'</></member>
31973199
<member><literal>'08002b-010203'</></member>
31983200
<member><literal>'0800.2b01.0203'</></member>
3199-
<member><literal>'08-00-2b-01-02-03'</></member>
3200-
<member><literal>'08:00:2b:01:02:03'</></member>
3201+
<member><literal>'08002b010203'</></member>
32013202
</simplelist>
32023203

3203-
whichwould all specify the same
3204-
address. Upper andlower case is accepted for the digits
3204+
These exampleswould all specify the same address. Upper and
3205+
lower case is accepted for the digits
32053206
<literal>a</> through <literal>f</>. Output is always in the
3206-
last of the forms shown.
3207+
first of the forms shown.
3208+
</para>
3209+
3210+
<para>
3211+
IEEE Std 802-2001 specifies the second shown form (with hyphens)
3212+
as the canonical form for MAC addresses, and specifies the first
3213+
form (with colons) as the bit-reversed notation, so that
3214+
08-00-2b-01-02-03 = 01:00:4D:08:04:0C. This convention is widely
3215+
ignored nowadays, and it is only relevant for obsolete network
3216+
protocols (such as Token Ring). PostgreSQL makes no provisions
3217+
for bit reversal, and all accepted formats use the canonical LSB
3218+
order.
3219+
</para>
3220+
3221+
<para>
3222+
The remaining four input formats are not part of any standard.
32073223
</para>
32083224
</sect2>
32093225

‎src/test/regress/expected/macaddr.out

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
--
2+
-- macaddr
3+
--
4+
CREATE TABLE macaddr_data (a int, b macaddr);
5+
INSERT INTO macaddr_data VALUES (1, '08:00:2b:01:02:03');
6+
INSERT INTO macaddr_data VALUES (2, '08-00-2b-01-02-03');
7+
INSERT INTO macaddr_data VALUES (3, '08002b:010203');
8+
INSERT INTO macaddr_data VALUES (4, '08002b-010203');
9+
INSERT INTO macaddr_data VALUES (5, '0800.2b01.0203');
10+
INSERT INTO macaddr_data VALUES (6, '08002b010203');
11+
INSERT INTO macaddr_data VALUES (7, '0800:2b01:0203'); -- invalid
12+
ERROR: invalid input syntax for type macaddr: "0800:2b01:0203"
13+
LINE 1: INSERT INTO macaddr_data VALUES (7, '0800:2b01:0203');
14+
^
15+
INSERT INTO macaddr_data VALUES (8, 'not even close'); -- invalid
16+
ERROR: invalid input syntax for type macaddr: "not even close"
17+
LINE 1: INSERT INTO macaddr_data VALUES (8, 'not even close');
18+
^
19+
INSERT INTO macaddr_data VALUES (10, '08:00:2b:01:02:04');
20+
INSERT INTO macaddr_data VALUES (11, '08:00:2b:01:02:02');
21+
INSERT INTO macaddr_data VALUES (12, '08:00:2a:01:02:03');
22+
INSERT INTO macaddr_data VALUES (13, '08:00:2c:01:02:03');
23+
INSERT INTO macaddr_data VALUES (14, '08:00:2a:01:02:04');
24+
SELECT * FROM macaddr_data;
25+
a | b
26+
----+-------------------
27+
1 | 08:00:2b:01:02:03
28+
2 | 08:00:2b:01:02:03
29+
3 | 08:00:2b:01:02:03
30+
4 | 08:00:2b:01:02:03
31+
5 | 08:00:2b:01:02:03
32+
6 | 08:00:2b:01:02:03
33+
10 | 08:00:2b:01:02:04
34+
11 | 08:00:2b:01:02:02
35+
12 | 08:00:2a:01:02:03
36+
13 | 08:00:2c:01:02:03
37+
14 | 08:00:2a:01:02:04
38+
(11 rows)
39+
40+
CREATE INDEX macaddr_data_btree ON macaddr_data USING btree (b);
41+
CREATE INDEX macaddr_data_hash ON macaddr_data USING hash (b);
42+
SELECT a, b, trunc(b) FROM macaddr_data ORDER BY 2, 1;
43+
a | b | trunc
44+
----+-------------------+-------------------
45+
12 | 08:00:2a:01:02:03 | 08:00:2a:00:00:00
46+
14 | 08:00:2a:01:02:04 | 08:00:2a:00:00:00
47+
11 | 08:00:2b:01:02:02 | 08:00:2b:00:00:00
48+
1 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
49+
2 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
50+
3 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
51+
4 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
52+
5 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
53+
6 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
54+
10 | 08:00:2b:01:02:04 | 08:00:2b:00:00:00
55+
13 | 08:00:2c:01:02:03 | 08:00:2c:00:00:00
56+
(11 rows)
57+
58+
SELECT b < '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
59+
?column?
60+
----------
61+
t
62+
(1 row)
63+
64+
SELECT b > '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
65+
?column?
66+
----------
67+
f
68+
(1 row)
69+
70+
SELECT b > '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
71+
?column?
72+
----------
73+
f
74+
(1 row)
75+
76+
SELECT b <= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
77+
?column?
78+
----------
79+
t
80+
(1 row)
81+
82+
SELECT b >= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
83+
?column?
84+
----------
85+
f
86+
(1 row)
87+
88+
SELECT b = '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- true
89+
?column?
90+
----------
91+
t
92+
(1 row)
93+
94+
SELECT b <> '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
95+
?column?
96+
----------
97+
t
98+
(1 row)
99+
100+
SELECT b <> '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
101+
?column?
102+
----------
103+
f
104+
(1 row)
105+
106+
DROP TABLE macaddr_data;

‎src/test/regress/parallel_schedule

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ----------
2-
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.47 2008/04/10 22:25:26 tgl Exp $
2+
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.48 2008/10/03 15:37:18 petere Exp $
33
#
44
# By convention, we put no more than twenty tests in any one parallel group;
55
# this limits the number of connections needed to run the tests.
@@ -18,7 +18,7 @@ test: numerology
1818
# ----------
1919
# The second group of parallel tests
2020
# ----------
21-
test: point lseg box path polygon circle date time timetz timestamp timestamptz interval abstime reltime tinterval inet tstypes comments
21+
test: point lseg box path polygon circle date time timetz timestamp timestamptz interval abstime reltime tinterval inetmacaddrtstypes comments
2222

2323
# ----------
2424
# Another group of parallel tests

‎src/test/regress/serial_schedule

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.44 2008/04/10 22:25:26 tgl Exp $
1+
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.45 2008/10/03 15:37:18 petere Exp $
22
# This should probably be in an order similar to parallel_schedule.
33
test: boolean
44
test: char
@@ -35,6 +35,7 @@ test: abstime
3535
test: reltime
3636
test: tinterval
3737
test: inet
38+
test: macaddr
3839
test: tstypes
3940
test: comments
4041
test: geometry

‎src/test/regress/sql/macaddr.sql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--
2+
-- macaddr
3+
--
4+
5+
CREATETABLEmacaddr_data (aint, bmacaddr);
6+
7+
INSERT INTO macaddr_dataVALUES (1,'08:00:2b:01:02:03');
8+
INSERT INTO macaddr_dataVALUES (2,'08-00-2b-01-02-03');
9+
INSERT INTO macaddr_dataVALUES (3,'08002b:010203');
10+
INSERT INTO macaddr_dataVALUES (4,'08002b-010203');
11+
INSERT INTO macaddr_dataVALUES (5,'0800.2b01.0203');
12+
INSERT INTO macaddr_dataVALUES (6,'08002b010203');
13+
INSERT INTO macaddr_dataVALUES (7,'0800:2b01:0203');-- invalid
14+
INSERT INTO macaddr_dataVALUES (8,'not even close');-- invalid
15+
16+
INSERT INTO macaddr_dataVALUES (10,'08:00:2b:01:02:04');
17+
INSERT INTO macaddr_dataVALUES (11,'08:00:2b:01:02:02');
18+
INSERT INTO macaddr_dataVALUES (12,'08:00:2a:01:02:03');
19+
INSERT INTO macaddr_dataVALUES (13,'08:00:2c:01:02:03');
20+
INSERT INTO macaddr_dataVALUES (14,'08:00:2a:01:02:04');
21+
22+
SELECT*FROM macaddr_data;
23+
24+
CREATEINDEXmacaddr_data_btreeON macaddr_data USING btree (b);
25+
CREATEINDEXmacaddr_data_hashON macaddr_data USING hash (b);
26+
27+
SELECT a, b, trunc(b)FROM macaddr_dataORDER BY2,1;
28+
29+
SELECT b<'08:00:2b:01:02:04'FROM macaddr_dataWHERE a=1;-- true
30+
SELECT b>'08:00:2b:01:02:04'FROM macaddr_dataWHERE a=1;-- false
31+
SELECT b>'08:00:2b:01:02:03'FROM macaddr_dataWHERE a=1;-- false
32+
SELECT b<='08:00:2b:01:02:04'FROM macaddr_dataWHERE a=1;-- true
33+
SELECT b>='08:00:2b:01:02:04'FROM macaddr_dataWHERE a=1;-- false
34+
SELECT b='08:00:2b:01:02:03'FROM macaddr_dataWHERE a=1;-- true
35+
SELECT b<>'08:00:2b:01:02:04'FROM macaddr_dataWHERE a=1;-- true
36+
SELECT b<>'08:00:2b:01:02:03'FROM macaddr_dataWHERE a=1;-- false
37+
38+
DROPTABLE macaddr_data;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp