pgsql返回表错误:列引用不明确 [英] pgsql return table ERROR: column reference is ambiguous
本文介绍了pgsql返回表错误:列引用不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直收到此错误:列引用人"不明确.
I keep getting this ERROR: column reference "person" is ambiguous.
我需要返回一个TABLE(人整数).当我使用SETOF整数时,它工作正常,但是在这种情况下,它不起作用.我的另一个函数recurse()可以很好地返回一组整数.
It is required of me to return a TABLE (person integer). It works fine when I use SETOF integer but in this instance it doesn't work. My other function recurse() returns a set of integers perfectly well.
CREATE OR REPLACE FUNCTION try(_group text) RETURNS TABLE (person integer) AS $$
DECLARE
_init_id integer;
_record integer;
BEGIN
SELECT id INTO _init_id FROM egroups WHERE name = _group;
FOR _record in SELECT person FROM egroupdata WHERE egroup IN (SELECT recurse(_init_id))
LOOP
RETURN NEXT;
END LOOP;
END;
$$ language plpgsql stable;
推荐答案
列引用不明确是由于存在多个同名列.在这种情况下,我想这是一个返回表的怪癖.尝试将查询更改为:
Ambiguous column references are due to there being more than one column available of the same name. In this case I guess it's a quirk of returning a table. Try changing the query to:
SELECT egroupdata.person FROM egroupdata WHERE egroup IN (SELECT recurse(_init_id))
这将消除列引用的歧义.
This will disambiguate the column reference.
这篇关于pgsql返回表错误:列引用不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文