【问题标题】:How can you select into variable in PostgreSQL?如何在 PostgreSQL 中选择变量?
【发布时间】:2020-08-27 06:05:38
【问题描述】:

我有以下功能:

Create or Replace Function someFunction([parameter1], [parameter2]) Returns Integer As $$
Declare
    someInt_ integer;
    totalRows_ integer;
Begin
    SELECT x INTO someInt_, COUNT(*) INTO totalRows_ 
    FROM [table]
    WHERE [some conditions];

    [more code]
End;
$$ Language 'plpgsql';

问题是我收到以下错误:

ERROR:  «count» is not a known variable
LINE 6:  SELECT x INTO someInt_, COUNT(*) INTO totalRows_ ...
                                 ^
SQL state: 42601
Character: 181

我该如何解决这个问题?

我知道很多数据丢失了,比如退货。这是因为我已经简化了它,因为变量是另一种语言。

【问题讨论】:

    标签: postgresql select plpgsql


    【解决方案1】:

    INTO 位于所有列之后:

    SELECT x, COUNT(*)
       INTO someInt_, totalRows_ 
    FROM [table]
    WHERE [some conditions];
    

    【讨论】:

      猜你喜欢
      • 2012-11-25
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 2012-07-21
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多