Re: UPDATE-FROM and INNER-JOIN - Mailing list pgsql-general

From David G. Johnston
Subject Re: UPDATE-FROM and INNER-JOIN
Date
Msg-id CAKFQuwZ3jzHUVMJ533OhgmrO8hYkOugRAHJN8avZtOLkQxsfTg@mail.gmail.com
Whole thread Raw
In response to Re: UPDATE-FROM and INNER-JOIN  (Dominique Devienne <ddevienne@gmail.com>)
List pgsql-general
On Mon, Aug 5, 2024 at 7:36 AM Dominique Devienne <ddevienne@gmail.com> wrote:
I'd rather SQLite and PostgreSQL continue to agree on this,
but not in a restrictive way.

I.e., you want to support the SQL Server syntax; allow the table named in UPDATE to be repeated, without an alias, in which case it is taken to represent the table being updated.  And then allow the usual FROM clause to take form.

Personally I get around this by simply doing:

UPDATE tbl
FROM (...) AS to_update

A bit more verbose in the typical case but the subquery in FROM can be separately executed during development then just plugged in.  There is no noise in the outer where clause since its only purpose is to join the subquery to the table to be updated.  The subquery has the full separation of filters from joins that one would like to have.

David J.

pgsql-general by date:

Previous
From: Dominique Devienne
Date:
Subject: Re: UPDATE-FROM and INNER-JOIN
Next
From: Tom Lane
Date:
Subject: Re: UPDATE-FROM and INNER-JOIN