public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: Ray O'Donnell <[email protected]>
Cc: 'PostgreSQL' <[email protected]>
Subject: Re: Combining scalar and row types in RETURNING
Date: Tue, 03 Jun 2025 12:53:58 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <01020197369aac89-01a7b7b4-b775-471e-ac8e-de8b28d87008-000000@eu-west-1.amazonses.com>
References: <01020197369aac89-01a7b7b4-b775-471e-ac8e-de8b28d87008-000000@eu-west-1.amazonses.com>
"Ray O'Donnell" <[email protected]> writes:
> Can you combine scalar and row types in a RETURNING clause?
I think so.
> declare
> m_action text;
> m_new_data record;
> begin
> merge into my_table t
> using (
> ....
> ) s
> on (t.id = s.id)
> when matched then
> update .....
> when not matched then
> insert .....
> returning
> merge_action(), t.*
> into
> m_action, m_new_data;
I think the problem here is that "t.*" gets expanded into a list of
all of t's columns, just as would happen in a SELECT's output list.
Try
returning merge_action(), t
It might also be necessary to declare the target variable
"m_new_data" as being of type my_table rather than generic
"record"; not sure about that.
regards, tom lane
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Combining scalar and row types in RETURNING
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox