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');
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');
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;
26 ----+-------------------
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
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;
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
58 SELECT b < '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
64 SELECT b > '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
70 SELECT b > '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
76 SELECT b <= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
82 SELECT b >= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
88 SELECT b = '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- true
94 SELECT b <> '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
100 SELECT b <> '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
106 DROP TABLE macaddr_data;