代码之家  ›  专栏  ›  技术社区  ›  nobody

postgresql-Mac地址Regex

  •  0
  • nobody  · 技术社区  · 7 年前

    我试图使用Greenplum中的以下查询检索具有正确mac地址的所有行,但我也得到了一些包含垃圾数据的行,如:??:??:??:??:??:??:??:??。当我将列传递给另一个函数时,我得到一个错误

    错误:“”不是有效的十六进制数字

    这是我的选择查询

    select * from table where mac_address like '%:%:%:%:%:%' 
                        and (length(mac_address)) = 17 
                        and mac_address like '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
    

    如何从Greenplum中的列中筛选出不正确的mac\U地址?

    1 回复  |  直到 7 年前
        1
  •  0
  •   nobody    7 年前

    我自己找到的, mac_address ~ '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'

    select * from table where mac_address like '%:%:%:%:%:%' 
                        AND (length(mac_address)) = 17 
                        AND mac_address ~ '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
    limit 100;