Re: Combining scalar and row types in RETURNING

From: Ray O'Donnell <ray(at)rodonnell(dot)ie>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: 'PostgreSQL' <pgsql-general(at)postgresql(dot)org>
Subject: Re: Combining scalar and row types in RETURNING
Date: 2025-06-03 20:08:48
Message-ID: 0102019737692b90-b251a7ea-b3c5-4477-afff-5986a149580a-000000@eu-west-1.amazonses.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 03/06/2025 20:01, Adrian Klaver wrote:
> On 6/3/25 11:18, Ray O'Donnell wrote:
>> On 03/06/2025 17:53, Tom Lane wrote:
>
>> Thanks a million for the explanation, Tom - that makes sense. I tried
>> what you suggested, with mixed results:
>>
>> (i) Running the MERGE as a stand-alone query, with just RETURNING...
>> , worked - I got a scalar and a row as expected.
>>
>> (ii) Running it in a function (actually a DO block), with m_new
>> correctly declared as the table type, failed with the same error as
>> before.
>>
>> (iii) Running (ii) but with the order of the items in RETURNING
>> reversed -
>>
>>      ... returning t, merge_action() into m_new, m_action
>>
>> - gave me a different error:
>>
>> ERROR:  record variable cannot be part of multiple-item INTO list
>> LINE 53:         m, merge_action() into m_new, m_action
>>
>> ...which seems to answer my question definitively.
>
> This:
>
> ... returning t, merge_action() into m_new, m_action
>
> does not match this:
>
> LINE 53:         m, merge_action() into m_new, m_action
>
>
> Is this a copy and paste error or two different invocations of the
> function?

Whoops, sorry, yes, that's a copy-and-paste error - the target table is
aliased as "m" in my original.

Ray.

--
Raymond O'Donnell // Galway // Ireland
ray(at)rodonnell(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2025-06-04 00:23:40 Re: Sudden increase in n_dead_tup with no corresponding insert/update/delete
Previous Message Tom Lane 2025-06-03 19:31:34 Re: Combining scalar and row types in RETURNING