1

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.

3
  • Is this from a plpgsql function definition? Can you provide some more complete code snippets including the complete function definition as well as the table definition? Commented Sep 1, 2016 at 3:01
  • Yes it is. It's a snippet from within a (large) plpgsql function. It's also not just INSERT statements but this error appears in other functions as well seemingly random ways. Is it somehow clashing with column names defined in a RETURNS TABLE() ? I can't narrow down the exact cause. Commented Sep 1, 2016 at 3:43
  • Well, I cannot reproduce this. You have to provide a minimal complete example. Commented Sep 1, 2016 at 8:50

1 Answer 1

8

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:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.