Add regression test for macaddr type. Enhance documentation about accepted
input formats.
This commit is contained in:
parent
0e4896d53e
commit
6761a0309b
|
@ -1,4 +1,4 @@
|
|||
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.228 2008/09/11 15:27:30 tgl Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.229 2008/10/03 15:37:18 petere Exp $ -->
|
||||
|
||||
<chapter id="datatype">
|
||||
<title id="datatype-title">Data Types</title>
|
||||
|
@ -3187,23 +3187,39 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
|
|||
</indexterm>
|
||||
|
||||
<para>
|
||||
The <type>macaddr</> type stores MAC addresses, i.e., Ethernet
|
||||
card hardware addresses (although MAC addresses are used for
|
||||
other purposes as well). Input is accepted in various customary
|
||||
formats, including
|
||||
The <type>macaddr</> type stores MAC addresses, known for example
|
||||
from Ethernet card hardware addresses (although MAC addresses are
|
||||
used for other purposes as well). Input is accepted in the
|
||||
following formats:
|
||||
|
||||
<simplelist>
|
||||
<member><literal>'08:00:2b:01:02:03'</></member>
|
||||
<member><literal>'08-00-2b-01-02-03'</></member>
|
||||
<member><literal>'08002b:010203'</></member>
|
||||
<member><literal>'08002b-010203'</></member>
|
||||
<member><literal>'0800.2b01.0203'</></member>
|
||||
<member><literal>'08-00-2b-01-02-03'</></member>
|
||||
<member><literal>'08:00:2b:01:02:03'</></member>
|
||||
<member><literal>'08002b010203'</></member>
|
||||
</simplelist>
|
||||
|
||||
which would all specify the same
|
||||
address. Upper and lower case is accepted for the digits
|
||||
These examples would all specify the same address. Upper and
|
||||
lower case is accepted for the digits
|
||||
<literal>a</> through <literal>f</>. Output is always in the
|
||||
last of the forms shown.
|
||||
first of the forms shown.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
IEEE Std 802-2001 specifies the second shown form (with hyphens)
|
||||
as the canonical form for MAC addresses, and specifies the first
|
||||
form (with colons) as the bit-reversed notation, so that
|
||||
08-00-2b-01-02-03 = 01:00:4D:08:04:0C. This convention is widely
|
||||
ignored nowadays, and it is only relevant for obsolete network
|
||||
protocols (such as Token Ring). PostgreSQL makes no provisions
|
||||
for bit reversal, and all accepted formats use the canonical LSB
|
||||
order.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The remaining four input formats are not part of any standard.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
--
|
||||
-- macaddr
|
||||
--
|
||||
CREATE TABLE macaddr_data (a int, b macaddr);
|
||||
INSERT INTO macaddr_data VALUES (1, '08:00:2b:01:02:03');
|
||||
INSERT INTO macaddr_data VALUES (2, '08-00-2b-01-02-03');
|
||||
INSERT INTO macaddr_data VALUES (3, '08002b:010203');
|
||||
INSERT INTO macaddr_data VALUES (4, '08002b-010203');
|
||||
INSERT INTO macaddr_data VALUES (5, '0800.2b01.0203');
|
||||
INSERT INTO macaddr_data VALUES (6, '08002b010203');
|
||||
INSERT INTO macaddr_data VALUES (7, '0800:2b01:0203'); -- invalid
|
||||
ERROR: invalid input syntax for type macaddr: "0800:2b01:0203"
|
||||
LINE 1: INSERT INTO macaddr_data VALUES (7, '0800:2b01:0203');
|
||||
^
|
||||
INSERT INTO macaddr_data VALUES (8, 'not even close'); -- invalid
|
||||
ERROR: invalid input syntax for type macaddr: "not even close"
|
||||
LINE 1: INSERT INTO macaddr_data VALUES (8, 'not even close');
|
||||
^
|
||||
INSERT INTO macaddr_data VALUES (10, '08:00:2b:01:02:04');
|
||||
INSERT INTO macaddr_data VALUES (11, '08:00:2b:01:02:02');
|
||||
INSERT INTO macaddr_data VALUES (12, '08:00:2a:01:02:03');
|
||||
INSERT INTO macaddr_data VALUES (13, '08:00:2c:01:02:03');
|
||||
INSERT INTO macaddr_data VALUES (14, '08:00:2a:01:02:04');
|
||||
SELECT * FROM macaddr_data;
|
||||
a | b
|
||||
----+-------------------
|
||||
1 | 08:00:2b:01:02:03
|
||||
2 | 08:00:2b:01:02:03
|
||||
3 | 08:00:2b:01:02:03
|
||||
4 | 08:00:2b:01:02:03
|
||||
5 | 08:00:2b:01:02:03
|
||||
6 | 08:00:2b:01:02:03
|
||||
10 | 08:00:2b:01:02:04
|
||||
11 | 08:00:2b:01:02:02
|
||||
12 | 08:00:2a:01:02:03
|
||||
13 | 08:00:2c:01:02:03
|
||||
14 | 08:00:2a:01:02:04
|
||||
(11 rows)
|
||||
|
||||
CREATE INDEX macaddr_data_btree ON macaddr_data USING btree (b);
|
||||
CREATE INDEX macaddr_data_hash ON macaddr_data USING hash (b);
|
||||
SELECT a, b, trunc(b) FROM macaddr_data ORDER BY 2, 1;
|
||||
a | b | trunc
|
||||
----+-------------------+-------------------
|
||||
12 | 08:00:2a:01:02:03 | 08:00:2a:00:00:00
|
||||
14 | 08:00:2a:01:02:04 | 08:00:2a:00:00:00
|
||||
11 | 08:00:2b:01:02:02 | 08:00:2b:00:00:00
|
||||
1 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
|
||||
2 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
|
||||
3 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
|
||||
4 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
|
||||
5 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
|
||||
6 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
|
||||
10 | 08:00:2b:01:02:04 | 08:00:2b:00:00:00
|
||||
13 | 08:00:2c:01:02:03 | 08:00:2c:00:00:00
|
||||
(11 rows)
|
||||
|
||||
SELECT b < '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT b > '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
|
||||
?column?
|
||||
----------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
SELECT b > '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
|
||||
?column?
|
||||
----------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
SELECT b <= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT b >= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
|
||||
?column?
|
||||
----------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
SELECT b = '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- true
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT b <> '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT b <> '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
|
||||
?column?
|
||||
----------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
DROP TABLE macaddr_data;
|
|
@ -1,5 +1,5 @@
|
|||
# ----------
|
||||
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.47 2008/04/10 22:25:26 tgl Exp $
|
||||
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.48 2008/10/03 15:37:18 petere Exp $
|
||||
#
|
||||
# By convention, we put no more than twenty tests in any one parallel group;
|
||||
# this limits the number of connections needed to run the tests.
|
||||
|
@ -18,7 +18,7 @@ test: numerology
|
|||
# ----------
|
||||
# The second group of parallel tests
|
||||
# ----------
|
||||
test: point lseg box path polygon circle date time timetz timestamp timestamptz interval abstime reltime tinterval inet tstypes comments
|
||||
test: point lseg box path polygon circle date time timetz timestamp timestamptz interval abstime reltime tinterval inet macaddr tstypes comments
|
||||
|
||||
# ----------
|
||||
# Another group of parallel tests
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.44 2008/04/10 22:25:26 tgl Exp $
|
||||
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.45 2008/10/03 15:37:18 petere Exp $
|
||||
# This should probably be in an order similar to parallel_schedule.
|
||||
test: boolean
|
||||
test: char
|
||||
|
@ -35,6 +35,7 @@ test: abstime
|
|||
test: reltime
|
||||
test: tinterval
|
||||
test: inet
|
||||
test: macaddr
|
||||
test: tstypes
|
||||
test: comments
|
||||
test: geometry
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
--
|
||||
-- macaddr
|
||||
--
|
||||
|
||||
CREATE TABLE macaddr_data (a int, b macaddr);
|
||||
|
||||
INSERT INTO macaddr_data VALUES (1, '08:00:2b:01:02:03');
|
||||
INSERT INTO macaddr_data VALUES (2, '08-00-2b-01-02-03');
|
||||
INSERT INTO macaddr_data VALUES (3, '08002b:010203');
|
||||
INSERT INTO macaddr_data VALUES (4, '08002b-010203');
|
||||
INSERT INTO macaddr_data VALUES (5, '0800.2b01.0203');
|
||||
INSERT INTO macaddr_data VALUES (6, '08002b010203');
|
||||
INSERT INTO macaddr_data VALUES (7, '0800:2b01:0203'); -- invalid
|
||||
INSERT INTO macaddr_data VALUES (8, 'not even close'); -- invalid
|
||||
|
||||
INSERT INTO macaddr_data VALUES (10, '08:00:2b:01:02:04');
|
||||
INSERT INTO macaddr_data VALUES (11, '08:00:2b:01:02:02');
|
||||
INSERT INTO macaddr_data VALUES (12, '08:00:2a:01:02:03');
|
||||
INSERT INTO macaddr_data VALUES (13, '08:00:2c:01:02:03');
|
||||
INSERT INTO macaddr_data VALUES (14, '08:00:2a:01:02:04');
|
||||
|
||||
SELECT * FROM macaddr_data;
|
||||
|
||||
CREATE INDEX macaddr_data_btree ON macaddr_data USING btree (b);
|
||||
CREATE INDEX macaddr_data_hash ON macaddr_data USING hash (b);
|
||||
|
||||
SELECT a, b, trunc(b) FROM macaddr_data ORDER BY 2, 1;
|
||||
|
||||
SELECT b < '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
|
||||
SELECT b > '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
|
||||
SELECT b > '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
|
||||
SELECT b <= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
|
||||
SELECT b >= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
|
||||
SELECT b = '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- true
|
||||
SELECT b <> '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
|
||||
SELECT b <> '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
|
||||
|
||||
DROP TABLE macaddr_data;
|
Loading…
Reference in New Issue