Database Reference
In-Depth Information
-[ RECORD 4 ]
a | 3
b | 2
c | 1
-[ RECORD 5 ]
a | 2
b | 3
c | 1
-[ RECORD 6 ]
a | 2
b | 1
c | 3
This works well, but does seem a bit verbose for what is a pretty simple operation.
This is due to the fact that we can't directly call RETURN NEXT a.b.c , but need to
first assign values to variables declared by the INOUT incantations. We also want to
avoid the even clumsier syntax of tmp = a; a = b; b = tmp .
Due to design decisions in the PL/pgSQL language, there is currently no good way
to construct the return structure at runtime, that is, no RETURN a,b,c .
However, let's try to do it anyway and see what happens.
Using RETURNS TABLE
You might think that if there are no visible OUT parameters in a function declared as
RETURNS TABLE(...) , the following code might work:
CREATE FUNCTION permutations2(a int, b int, c
int)RETURNS TABLE(a int, b int, c int)
AS $$
BEGIN
RETURN NEXT a,b,c;
END;
$$ LANGUAGE plpgsql;
Search WWH ::




Custom Search