This instruction works:
SELECT INTO unsolvedNodes array_agg(DISTINCT idDestination)
FROM road
WHERE idOrigin = ANY(solvedNodes)
AND NOT (idDestination = ANY(solvedNodes));
But I would like to use something this way:
SELECT INTO unsolvedNodes array_agg(DISTINCT idDestination), lengths array_agg(length)
FROM road
WHERE idOrigin = ANY(solvedNodes)
AND NOT (idDestination = ANY(solvedNodes));
How to use only one "SELECT INTO" instruction to set multiple variables?
In PL/pgSQL you can
SELECT INTO
as many variables at once as you like directly. You just had the syntax backwards:You have the keyword
INTO
followed by a list of target variables, and you have a correspondingSELECT
list. The target of theINTO
clause can be (quoting the manual here):Also:
This is not to be confused with
SELECT INTO
in the SQL dialect of Postgres - which nobody should be using any more. It goes against standard SQL and will eventually be removed, most likely. The manual actively discourages its continued use:Yes,
OR