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

前端之家收集整理的这篇文章主要介绍了postgresql – Postgres函数将查询结果分配给多个变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在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.

@H_404_18@

所以这应该工作:

SELECT col1,col2 INTO a,b FROM tbl WHERE...;
原文链接:https://www.f2er.com/postgresql/192254.html

猜你在找的Postgre SQL相关文章