加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – Postgres函数将查询结果分配给多个变量

发布时间:2020-12-13 16:20:26 所属栏目:百科 来源:网络整理
导读:我需要在Postgres函数中为2变量赋值,如下所示. a := select col1 from tbl where ...b := select col2 from tbl where ... 如何在一个行命令中为2个变量分配2个值? 喜欢 a,b := select col1,col2 from tbl where ... 如 “40.5.3. Executing a Query with a
我需要在Postgres函数中为2变量赋值,如下所示.
a := select col1 from tbl where ...
b := select col2 from tbl where ...

如何在一个行命令中为2个变量分配2个值?

喜欢

a,b := select col1,col2 from tbl where ...
如 “40.5.3. Executing a Query with a Single-row Result”所述(强调我的):

The result of a SQL command yielding a single row (possibly of multiple columns) can be assigned to a record variable,row-type variable,or list of scalar variables. This is done by writing the base SQL command and adding an INTO clause.

所以这应该工作:

SELECT col1,col2 INTO a,b FROM tbl WHERE...;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读