postgresql pgsql 返回表错误:列引用不明确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10750707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pgsql return table ERROR: column reference is ambiguous
提问by ryantata
I keep getting this ERROR: column reference "person" is ambiguous.
我不断收到此错误:列引用“人”不明确。
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.
我需要返回一个 TABLE(个人整数)。当我使用 SETOF 整数时它工作正常,但在这种情况下它不起作用。我的另一个函数 recurse() 很好地返回了一组整数。
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;
回答by Philip Couling
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.
这将消除列引用的歧义。