PostgreSQL-INSERT RETURNING INTO歧义列参考 [英] Postgresql - INSERT RETURNING INTO ambiguous column reference

查看:76
本文介绍了PostgreSQL-INSERT RETURNING INTO歧义列参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以礼貌地解释这种疯狂吗?

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.

推荐答案

INOUT参数(包括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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆