PostgreSQL-INSERT RETURNING INTO歧义列参考 [英] Postgresql - INSERT RETURNING INTO ambiguous column reference
问题描述
有人可以礼貌地解释这种疯狂吗?
Can someone politely explain this crazyness?
INSERT INTO "dbo"."UserProfile" ("FirstName")
VALUES('John')
RETURNING "UserProfileId" INTO _UserProfileId;
抛出一个模棱两可的引用错误,但这可以正确执行:
throws an ambiguous reference error, however this correctly executes:
INSERT INTO "dbo"."UserProfile" ("FirstName")
VALUES('John')
RETURNING "dbo"."UserProfile"."UserProfileId" INTO _UserProfileId;
_UserProfileId
是声明的整数变量.我在手册中找不到对此语法的任何引用,或者为什么这在任何情况下都将是模棱两可的.
_UserProfileId
is a declared integer variable. I couldn't find any references to this syntax in the manual or why on earth this would be ambiguous in any way.
推荐答案
IN
和OUT
参数(包括RETURNS TABLE
中的列)在plpgsql函数主体中的每个SQL命令中都是可见的.
IN
and OUT
parameters (including columns in RETURNS TABLE
) are visible inside every SQL command in the body of a plpgsql function.
如果查询中具有相同名称的列,则必须对它们进行表限定,以使其明确.在您的情况下,表名可以:
If you have columns of the same name in your query, you have to table-qualify them to make it unambiguous. In your case, the table name would do:
... RETURNING "UserProfile"."UserProfileId" INTO _UserProfileId;
相关:
- How to return result of a SELECT inside a function in PostgreSQL?
- Naming conflict between function parameter and result of JOIN with USING clause
这篇关于PostgreSQL-INSERT RETURNING INTO歧义列参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!