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, '0800-2b01-0203');
11 INSERT INTO macaddr_data VALUES (7, '08002b010203');
12 INSERT INTO macaddr_data VALUES (8, '0800:2b01:0203'); -- invalid
13 ERROR: invalid input syntax for type macaddr: "0800:2b01:0203"
14 LINE 1: INSERT INTO macaddr_data VALUES (8, '0800:2b01:0203');
16 INSERT INTO macaddr_data VALUES (9, 'not even close'); -- invalid
17 ERROR: invalid input syntax for type macaddr: "not even close"
18 LINE 1: INSERT INTO macaddr_data VALUES (9, 'not even close');
20 INSERT INTO macaddr_data VALUES (10, '08:00:2b:01:02:04');
21 INSERT INTO macaddr_data VALUES (11, '08:00:2b:01:02:02');
22 INSERT INTO macaddr_data VALUES (12, '08:00:2a:01:02:03');
23 INSERT INTO macaddr_data VALUES (13, '08:00:2c:01:02:03');
24 INSERT INTO macaddr_data VALUES (14, '08:00:2a:01:02:04');
25 SELECT * FROM macaddr_data;
27 ----+-------------------
35 10 | 08:00:2b:01:02:04
36 11 | 08:00:2b:01:02:02
37 12 | 08:00:2a:01:02:03
38 13 | 08:00:2c:01:02:03
39 14 | 08:00:2a:01:02:04
42 CREATE INDEX macaddr_data_btree ON macaddr_data USING btree (b);
43 CREATE INDEX macaddr_data_hash ON macaddr_data USING hash (b);
44 SELECT a, b, trunc(b) FROM macaddr_data ORDER BY 2, 1;
46 ----+-------------------+-------------------
47 12 | 08:00:2a:01:02:03 | 08:00:2a:00:00:00
48 14 | 08:00:2a:01:02:04 | 08:00:2a:00:00:00
49 11 | 08:00:2b:01:02:02 | 08:00:2b:00:00:00
50 1 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
51 2 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
52 3 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
53 4 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
54 5 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
55 6 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
56 7 | 08:00:2b:01:02:03 | 08:00:2b:00:00:00
57 10 | 08:00:2b:01:02:04 | 08:00:2b:00:00:00
58 13 | 08:00:2c:01:02:03 | 08:00:2c:00:00:00
61 SELECT b < '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
67 SELECT b > '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
73 SELECT b > '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
79 SELECT b <= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
85 SELECT b >= '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- false
91 SELECT b = '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- true
97 SELECT b <> '08:00:2b:01:02:04' FROM macaddr_data WHERE a = 1; -- true
103 SELECT b <> '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
109 SELECT ~b FROM macaddr_data;
126 SELECT b & '00:00:00:ff:ff:ff' FROM macaddr_data;
143 SELECT b | '01:02:03:04:05:06' FROM macaddr_data;
160 DROP TABLE macaddr_data;