提取字符串中特殊字符之间的子字符串

时间:2019-03-25 13:12:58

标签: postgresql amazon-web-services

我正在尝试从AWS ARN(Amazon资源编号)中提取Postgres RDS实例的账户名称和区域,并将其传递给另一个脚本。例如,对于ARN:

region= eu-central-1

在上面的示例中,我尝试提取accountnumber= 123456789777pytest --cov sample test.py

1 个答案:

答案 0 :(得分:2)

我们可以在此处尝试使用SPLIT_PART

with cte AS (
    select 'arn:aws:rds:eu-central-1:123456789777:db:testdb'::text as arn
)

select
    split_part(arn, ':', 4) as region,
    split_part(arn, ':', 5) as account_no
from cte;

enter image description here

Demo

相关问题