我有一张带有属性的表(ID int、SourceID int、TargetID int、TargetType int)
ID 源ID 目标ID -------------------- 1 123 456 2 456 789 3 1 123 4 456 1 5 2 1
我想找出所有循环引用。我想为此编写 PL/pgsql 函数。
这里 ID 4 的循环引用 = 456 1 123 456
我想找到这样的例子。谁能建议我如何进行此操作。
如何将下面的查询映射到postgres函数.
WITH RECURSIVE source (counter, product) AS (
SELECT
1, 1
UNION ALL
SELECT
counter + 1, product * (counter + 1)
FROM source
WHERE
counter < 10
)
SELECT counter, product FROM source;
Run Code Online (Sandbox Code Playgroud)
我是postgres的新手.我想使用PL/pgsql函数实现相同的功能.