Search code examples
clickhouse

How to reverse MACStringToOUI() in ClickHouse so I get the mac address with empty last 3 octets


SELECT MACStringToOUI('aa:bb:cc:dd:ee:ff')

gives me 11189196 which are the first three octets as a UInt64 number.

I'd like to convert it back to MacAddress so the desired result is aa:bb:cc:00:00:00.

I believe there's no native function for that. Do I have to move bits manually?


Solution

  • *256^3

    SELECT MACNumToString(MACStringToOUI('aa:bb:cc:dd:ee:ff')*256*256*256) r;
    Query id: 3a3637c3-d068-4b00-9024-01129517c3e2
    
    ┌─r─────────────────┐
    │ AA:BB:CC:00:00:00 │
    └───────────────────┘