解析字符串“projects/project/23”时可能会将其扩展为以下结果:
projects
projects/project
projects/project/23
我想我可以使用滞后/领先窗口函数并进行此 SQL 查询:
select lag(unnest, 1, '') OVER () || '/' || unnest AS unnest
from unnest(string_to_array('projects/project/23', '/'))
但它不起作用。怎么做?
谢谢你。
一种解决方案:
好的,我找到了一种解决方案(但我认为它不是最佳的)
WITH t AS (
SELECT row_number() OVER (),
string_to_array('projects/project/23', '/')
FROM unnest(string_to_array('projects/project/23', '/'))
)
SELECT array_to_string(string_to_array[1:t.row_number], '/')
FROM t