小编PL-*_*000的帖子

在 PostgreSQL 表中查找循环引用?

我有一张带有属性的表(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

我想找到这样的例子。谁能建议我如何进行此操作。

sql postgresql plpgsql circular-reference postgresql-9.1

6
推荐指数
1
解决办法
2390
查看次数

postgres中的递归函数

如何将下面的查询映射到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函数实现相同的功能.

postgresql plpgsql recursive-query postgresql-9.2

5
推荐指数
1
解决办法
1万
查看次数