选择多个属性

编程入门 行业动态 更新时间:2024-10-27 19:18:21
本文介绍了选择多个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

此说明有效:

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):

...记录变量,行变量或以下内容的逗号分隔列表 简单变量和记录/行字段.

...a record variable, a row variable, or a comma-separated list of simple variables and record/row fields.

也:

INTO子句几乎可以出现在SQL命令中的任何位置. 通常,它写在列表的前面或后面 SELECT命令中或命令末尾的select_expressions 对于其他命令类型.建议您遵循此 约定,以防PL/pgSQL解析器在将来的版本中变得更严格.

The INTO clause can appear almost anywhere in the SQL command. Customarily it is written either just before or just after the list of select_expressions in a SELECT command, or at the end of the command for other command types. It is recommended that you follow this convention in case the PL/pgSQL parser becomes stricter in future versions.

这与 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:

为此,最好在新代码中使用CREATE TABLE AS.

更多推荐

选择多个属性

本文发布于:2023-11-16 16:05:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!