pgsql return table ERROR: column reference is ambiguous

笑着哭i 提交于 2019-12-12 10:39:58

问题


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.

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;

回答1:


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.




回答2:


Of course ambiguous column references are due to the fact that an attribute with the same name is present in more than one table. But above response is not explaining what really should be done. I have the query:

select a.b, c.b from vsh_a a, vsh_b b where a.id = b.id

Replacing the first alias with the tablename will not help. What now?



来源:https://stackoverflow.com/questions/10750707/pgsql-return-table-error-column-reference-is-ambiguous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!