问题
I am trying to use "WITH" that is Common Table Expression within the function of PostgreSQL.
Here is the following example:
Example:
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;
Question: How to execute and get values into the above table using WITH within function?
回答1:
It it necessary to return table
Create or replace function withFunction()
returns table(phone1 text, phone2 text) as
then
select * from withFunction()
来源:https://stackoverflow.com/questions/24205381/how-to-write-withcte-within-function-in-postgresql