[英]Oracle connect by function alternate in Postgres
我在 oracle 中有以下查詢,我想遷移到 Postgres,有人可以幫我嗎?
唯一具有挑戰性的部分是通過命令連接。 Postgres 不支持它
WITH readyForHouseKeeper AS (
SELECT regexp_substr(system_file_path, '^.*/') AS path
FROM cognito.patent p
JOIN cognito.pat_tracking pt
ON p.ref_id = pt.pat_ref_id
AND p.language = 'es'
AND p.stage_id=80
AND pt.stage_id=80
AND pt.status_date BETWEEN (localtimestamp - INTERVAL '2' MONTH) AND (localtimestamp - INTERVAL '1' MONTH) -- between 60days and 30 days -- Frontfile
AND rownum < 50001
ORDER BY pt.status_date
)
SELECT h.path||' '|| fileType ||' 30 * f rm'
FROM readyForHouseKeeper h,
(
SELECT trim(regexp_substr(fileType,'[^;]+', 1, LEVEL)) AS fileType
FROM ( SELECT 'stripped_cxml_*;MachineOutput_NameFile_cxml_*;Low_Confidence_*;*ContentFile*' AS fileType)
CONNECT BY instr(fileType, ';', 1, LEVEL - 1) > 0
)
不需要 connect by 或遞歸查詢,只需使用string_to_table()
將字符串轉換為行
....
SELECT h.path||' '|| t.fileType ||' 30 * f rm'
from readyForHouseKeeper h,
lateral string_to_table('stripped_cxml_*;MachineOutput_NameFile_cxml_*;Low_Confidence_*;*ContentFile*', ';') as t(filetype)
雖然我更喜歡顯式交叉連接:
SELECT h.path||' '|| t.fileType ||' 30 * f rm'
from readyForHouseKeeper h --<< no comma!
cross join lateral string_to_table(...) as t(filetype)
或者,如果您使用的是較舊的 Postgres 版本:
....
SELECT h.path||' '|| t.fileType ||' 30 * f rm'
from readyForHouseKeeper h,
lateral unnest(string_to_array('stripped_cxml_*;MachineOutput_NameFile_cxml_*;Low_Confidence_*;*ContentFile*', ';')) as t(filetype)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.