From 6761a0309b1a611971a7138797cf38dab4618547 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter_e@gmx.net> Date: Fri, 3 Oct 2008 15:37:18 +0000 Subject: [PATCH] Add regression test for macaddr type. Enhance documentation about accepted input formats. --- doc/src/sgml/datatype.sgml | 36 ++++++--- src/test/regress/expected/macaddr.out | 106 ++++++++++++++++++++++++++ src/test/regress/parallel_schedule | 4 +- src/test/regress/serial_schedule | 3 +- src/test/regress/sql/macaddr.sql | 38 +++++++++ 5 files changed, 174 insertions(+), 13 deletions(-) create mode 100644 src/test/regress/expected/macaddr.out create mode 100644 src/test/regress/sql/macaddr.sql diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 0b969eaa22e..d05c93058a0 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -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> diff --git a/src/test/regress/expected/macaddr.out b/src/test/regress/expected/macaddr.out new file mode 100644 index 00000000000..0b2a96d2f7a --- /dev/null +++ b/src/test/regress/expected/macaddr.out @@ -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; diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule index f03d4179e1e..c00604ede59 100644 --- a/src/test/regress/parallel_schedule +++ b/src/test/regress/parallel_schedule @@ -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 diff --git a/src/test/regress/serial_schedule b/src/test/regress/serial_schedule index 34c75f6c5cd..88d0aba5f36 100644 --- a/src/test/regress/serial_schedule +++ b/src/test/regress/serial_schedule @@ -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 diff --git a/src/test/regress/sql/macaddr.sql b/src/test/regress/sql/macaddr.sql new file mode 100644 index 00000000000..ce8d9209329 --- /dev/null +++ b/src/test/regress/sql/macaddr.sql @@ -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; -- GitLab