首页 > 解决方案 > 从字符串中的名称值对中获取一个值

问题描述

对于以下示例,返回帐户 ID 123abc 的最佳方法是什么?

with 

pairs as (
select 'blah=foo|something=else|account_id=123abc|fruits=apples' pears
)

select [I want account_id] from pairs

标签: sqlpostgresql

解决方案


一种方法使用regexp_matches()

select (regexp_matches(pears, 'account_id=([^|]+)'))[1]
from pairs

推荐阅读