繁体   English   中英

Oracle 在 Postgres 中由 function 替代连接

[英]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)

问题未解决?试试以下方法:

Oracle 在 Postgres 中由 function 替代连接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2023 STACKOOM.COM