| From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
|---|---|
| To: | Färber, Franz-Josef (StMUK) <Franz-Josef(dot)Faerber(at)stmuk(dot)bayern(dot)de> |
| Cc: | "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: UPDATE myTable SET (myTable.*) = json_populate_record(...) ? |
| Date: | 2026-08-03 20:21:51 |
| Message-ID: | CAHyXU0znwmN4i_vOojKzWSZT_VvexavoWPmc3tA3p+Zw+dnHsw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Mon, Aug 3, 2026 at 4:19 AM Färber, Franz-Josef (StMUK) <
Franz-Josef(dot)Faerber(at)stmuk(dot)bayern(dot)de> wrote:
> Dear Postgres Community,
>
> cf. https://www.postgresql.org/docs/current/sql-update.html :
>
> As far as I understand, I can
>
> * UPDATE myTable SET col1 = val1, col2 = val2, ...
> * UPDATE myTable SET (col1, col2, ...) = <ROW-or-subselect>
>
> But I cannot, and I am missing that:
> * UPDATE myTable SET (myTable.*) = <ROW-or-subselect>
> * UPDATE myTable SET (col1, col2, ...) =
> json_populate_record(NULL::myTable, myJson) -- this is a function, not a
> ROW construct and not a subselect
>
What you *can* do is insert from json_populate_record, then write an ON
CONFLICT clause to set the rest of the columns. It's possible to do this
in a generic way with dynamic SQL if you assume that you are matching the
table's primary key and the rest of the columns are to be updated.
As others mentioned, SQL doesn't really have this, but if you are very
proficient with pl/pgsql you can work around it.
merlin
| From | Date | Subject | |
|---|---|---|---|
| Next Message | VERDIER Armand | 2026-08-04 09:27:43 | Incompatibility between pg_squeeze and pglogical |
| Previous Message | 2026-08-03 18:26:57 | AW: AW: UPDATE myTable SET (myTable.*) = json_populate_record(...) ? |