ERROR: a column definition list is required for functions returning "record"
错误二
1
ERROR: a column definition list is only allowed for functions returning "record"
上面具体错误原因暂时不分析,接下来针对上面 ERROR,通过实验来演示:.
错误一演示
创建测试表并插入数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
skytf=> create table test_result3 (id integer,name varchar(32),addr varchar(32),result varchar(32)); CREATE TABLE skytf=> insert into test_result3 select generate_series(1,10),'test_'|| generate_series(1,10),'no','no'; INSERT 010
skytf=> select * From test_result3; id | name | addr | result ----+---------+------+-------- 1 | test_1 | no | no 2 | test_2 | no | no 3 | test_3 | no | no 4 | test_4 | no | no 5 | test_5 | no | no 6 | test_6 | no | no 7 | test_7 | no | no 8 | test_8 | no | no 9 | test_9 | no | no 10 | test_10 | no | no (10 rows)
创建函数
1 2 3 4 5 6 7 8 9 10 11 12
CREATEORREPLACEFUNCTION skytf.func_test_result3_query ( in_id integer) RETURNS SETOF RECORDas $$ DECLARE v_rec RECORD; BEGIN returnqueryselect * from test_result3 whereid = in_id; return; END; $$ LANGUAGE PLPGSQL;
执行函数(不指定目标列)
1 2 3
skytf=> select * from func_test_result3_query(1); ERROR: a column definition list is required for functions returning "record" LINE 1: select * from func_test_result3_query(1);
备注:执行函数报错,提示需要指定 definition column。
执行函数(指定目标列)
1 2 3 4
skytf=> select * from func_test_result3_query(1) t(id integer,name varchar,addr varchar,result varchar); id | name | addr | result ----+--------+------+-------- 1 | test_1 | no | no
备注:在返回类型为 RECORD 函数,由于 RECORD 类型为不确定数据类型,在调用函数时需要指定返回类型目标列,
mydb=> select * From func_user_login(1) t ( username varchar, pwd varchar);
ERROR: a column definition list is only allowed for functions returning "record"
LINE 1: select * From func_user_login(1) t ( username varchar, pwd v...
^