在PostgreSQL 9.3中将select值赋给变量

在PostgreSQL 9.3中将select值赋给变量,postgresql,postgresql-9.3,Postgresql,Postgresql 9.3,我有下表: 示例: create table test ( id int, name varchar(10), city varchar(10) ); ERROR: syntax error at or near "SELECT" LINE 12: ident := SELECT ID from test; 我想将表中的ID值分配给函数中的变量 功能: create or replace function testing(ids int,names varchar(10),cit

我有下表:

示例

create table test
( 
 id int,
 name varchar(10),
 city varchar(10)
);
ERROR:  syntax error at or near "SELECT"
LINE 12:  ident := SELECT ID from test;
我想将表中的ID值分配给函数中的变量

功能:

create or replace function testing(ids int,names varchar(10),citys varchar(10)
returns void as
$body$
Declare
       ident int;
BEGIN
       ident := SELECT ID FROM test;
       raise info '%',ident;
END;
$body$
Language plpgsql;
错误详细信息

create table test
( 
 id int,
 name varchar(10),
 city varchar(10)
);
ERROR:  syntax error at or near "SELECT"
LINE 12:  ident := SELECT ID from test;

使用
选择。。。进入

create or replace function testing(ids int,names varchar(10),citys varchar(10)
returns void as
$body$
Declare
       ident int;
       foo   text;
BEGIN
       SELECT ID, some_col  
          into ident, foo 
       FROM test;
       raise info '%',ident;
END;
$body$
Language plpgsql;
手册中有更多详细信息和示例:

如果我想为多个变量分配多个值,该怎么办?如手册中所述:“其中目标可以是记录变量、行变量或简单变量和记录/行字段的逗号分隔列表”请参见我的编辑