我试图在PostgreSQL的功能中使用Common表达式的“WITH”。
以下是以下示例:
示例:
Create or replace function withFunction() returns void as
$Body$
Begin
WITH cmn_l1
AS
(
SELECT "PhoneNumber1","PhoneNumber2",
DENSE_RANK() OVER(Partition by "PhoneNumber1" Order By "PhoneNumber2" )FoundIn
From tablename;
)
SELECT DISTINCT * INTO temptable
FROM cmn_l1
WHERE FoundIn > 1;
end;
$Body$
language plpgsql;
问题:如何在函数内使用WITH执行并获取上表中的值?
答案 0 :(得分:1)
必须返回table
Create or replace function withFunction()
returns table(phone1 text, phone2 text) as
然后
select * from withFunction()