Skip to content

TRUNC

This function sets the last 3 bytes of a MACADDR value to zero or the last 5 bytes of a MACADDR8 value to zero.

TRUNC(macaddr | macaddr8)

where macaddr and macaddr8 are either columns or expressions with those data types or literal values in a valid format. Literal values must be preceded with the MACADDR or MACADDR8 keyword.

For example:

premdb=# \d ips
     Table "public.ips"
 Column |   Type   | Modifiers 
--------+----------+-----------
 c1     | ipv4     | 
 c2     | ipv6     | 
 c3     | macaddr  | 
 c4     | macaddr8 | 

Distribution: Hash (c1)

premdb=# select c3, c4 from ips;
       c3         |           c4            
-------------------+-------------------------
 10:20:30:40:00:00 | 10:20:30:40:00:00:00:00
(1 row)

premdb=# select trunc(c3), trunc(c4) from ips;
      trunc       |          trunc          
-------------------+-------------------------
 10:20:30:00:00:00 | 10:20:30:00:00:00:00:00
(1 row)
premdb=# select trunc(macaddr '10:20:30:00:00:00') from sys.const;
      trunc       
-------------------
 10:20:30:00:00:00
(1 row)

premdb=# select trunc(macaddr8 '10:20:30:00:00:00:00:00') from sys.const;
         trunc          
-------------------------
 10:20:30:00:00:00:00:00
(1 row)

Parent topic:Network Address Functions