问题描述
此说明有效:
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));
如何仅使用一条"SELECT INTO"指令来设置多个变量?
How to use only one "SELECT INTO" instruction to set multiple variables?
推荐答案
在 PL/pgSQL 中,您可以直接SELECT INTO
一次任意数量的变量.您只是向后使用了语法:
In PL/pgSQL you can SELECT INTO
as many variables at once as you like directly. You just had the syntax backwards:
SELECT INTO unsolvedNodes, lengths
array_agg(DISTINCT idDestination), array_agg(length)
FROM road
WHERE idOrigin = ANY(solvedNodes)
AND NOT (idDestination = ANY(solvedNodes));
您具有关键字INTO
,后跟目标变量列表,并且具有相应的SELECT
列表. INTO
子句的目标可以是(引用该手册这里):
You have the keyword INTO
followed by a list of target variables, and you have a corresponding SELECT
list. The target of the INTO
clause can be (quoting the manual here):
也:
这与 SELECT INTO
Postgres的SQL方言-没有人应该再使用.它违反标准SQL,最终很有可能会被删除.该手册积极劝阻其继续使用:
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:
这篇关于选择多个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!