Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

postgresql - INSERT INTO ... RETURNING - ambiguous column reference

Can someone politely explain this craziness?

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 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;

Details in the manual here.

Related:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...