PostgreSQL子串提取
我有一个名为“uri”的列,其值如下:PostgreSQL子串提取,postgresql,substring,Postgresql,Substring,我有一个名为“uri”的列,其值如下: file://c:\file1.txt file://\\1.1.1.1\folder1\folder1a\file2.txt file://d:\sub1\sub2\sub3\file3.txt 我正在尝试从uri中删除文件名以离开 file://c:\ file://\\1.1.1.1\folder1\folder1a\ file://d:\sub1\sub2\sub3\ 您可以使用regexp\u replace: with t (col) as
file://c:\file1.txt
file://\\1.1.1.1\folder1\folder1a\file2.txt
file://d:\sub1\sub2\sub3\file3.txt
我正在尝试从uri中删除文件名以离开
file://c:\
file://\\1.1.1.1\folder1\folder1a\
file://d:\sub1\sub2\sub3\
您可以使用
regexp\u replace
:
with t (col) as (
select 'file://c:\file1.txt' union all
select 'file://\\1.1.1.1\folder1\folder1a\file2.txt' union all
select 'file://d:\sub1\sub2\sub3\file3.txt'
)
select regexp_replace(col, '(^.*?)[^\\]*$', '\1') as output from t;
产生:
output
---------------------------------
file://c:\
file://\\1.1.1.1\folder1\folder1a\
file://d:\sub1\sub2\sub3\
你已经试过什么了?看看这个。regexp\u replace(您的列名称“^.+[/\]”,“”)