Re: RETURNS TABLE function: ERROR: column reference "word" is ambiguous

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: RETURNS TABLE function: ERROR: column reference "word" is ambiguous
Date: 2016-08-10 17:17:59
Message-ID: ca8b37b8-8734-0594-9b20-cb298b2d36f0@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/10/2016 10:05 AM, Alexander Farber wrote:
> Thank you Adrian and others -
>
> I am trying to replace INSERT into temp table in my custom function by
> RETURN NEXT, but get an error:
>
> CREATE OR REPLACE FUNCTION words_check_words(
> IN in_uid integer,
> IN in_gid integer,
> IN in_tiles jsonb)
> RETURNS TABLE(word varchar, score integer) AS
> $func$
> .......
>
> -- INSERT INTO _words(word, score)
> -- VALUES (upper(_word), _score);
>
> RETURN NEXT (word, score);
>
>
> ERROR: RETURN NEXT cannot have a parameter in function with OUT parameters
> LINE 98: RETURN NEXT (word, score);

With RETURN NEXT you have to build the table a row at a time where
RETURN NEXT is in a LOOP. You also need to assign to the OUT
parameters, in this case the fields in your RETURN TABLE. So something
like, inside LOOP:

word := upper(_word);
score := _score;

RETURN NEXT;

If I am following correctly.

>
> Regards
> Alex

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2016-08-10 17:19:07 Re: RETURNS TABLE function: ERROR: column reference "word" is ambiguous
Previous Message Alexander Farber 2016-08-10 17:05:22 Re: RETURNS TABLE function: ERROR: column reference "word" is ambiguous