【问题标题】:how to extract a word from string using substring function in PostgreSql如何使用 PostgreSql 中的子字符串函数从字符串中提取单词
【发布时间】:2021-09-11 19:49:07
【问题描述】:

这是字符串:atlngahpig001_to_atlngahpig002-GatewayCallStats 我需要从中提取 atlngahpig001 代替 altnagahpig001 可能还有其他的

谁能找到解决方案如何使用子字符串函数来获取它?

【问题讨论】:

    标签: postgresql substring grafana


    【解决方案1】:

    如果你需要一个更通用的解决方案,假设字符串格式是一致的,你可以使用,

    SELECT split_part('atlngahpig001_to_atlngahpig002-GatewayCallStats', '_', 1);
    

    【讨论】:

    • "我使用了以下子字符串 select substring("INSTANCE_ID" from '%_to_#"_%#"-%' for '#') 从中提取 atlngahpig002,这里是 "INSTANCE_ID" -atlngahpig001_to_atlngahpig002- GatewayCallStats,但我需要提取这个“atlngahpig001”,即第一个词,你能帮我吗?
    • select substring('atlngahpig001_to_atlngahpig002-GatewayCallStats' from '#"_%#"_to_%-%' for '#')
    【解决方案2】:

    这取决于您要如何查找字符串,但您可以这样做

    SELECT SUBSTRING('atlngahpig001_to_atlngahpig002-GatewayCallStats', 1, 13)
    

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2019-10-26
      • 1970-01-01
      • 2016-02-03
      • 2023-03-24
      • 2017-02-14
      • 2012-10-27
      • 1970-01-01
      • 2013-12-12
      相关资源
      最近更新 更多