Re: [PATCH] Implement INSERT SET syntax - Mailing list pgsql-hackers

From Marko Tiikkaja
Subject Re: [PATCH] Implement INSERT SET syntax
Date
Msg-id CAL9smLAsgNGFFOCZZmU+_H-Lyx76R-1OqUr2WQZLuDtQTUkbCQ@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Implement INSERT SET syntax  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On Fri, Nov 1, 2019 at 6:31 PM Robert Haas <robertmhaas@gmail.com> wrote:
On Sun, Aug 18, 2019 at 11:00 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Perhaps the way to resolve Peter's objection is to make the syntax
> more fully like UPDATE:
>
> INSERT INTO target SET c1 = x, c2 = y+z, ... FROM tables-providing-x-y-z
>
> (with the patch as-submitted corresponding to the case with an empty
> FROM clause, hence no variables in the expressions-to-be-assigned).
>
> Of course, this is not functionally distinct from
>
> INSERT INTO target(c1,c2,...) SELECT x, y+z, ... FROM tables-providing-x-y-z
>
> and it's fair to question whether it's worth supporting a nonstandard
> syntax just to allow the target column names to be written closer to
> the expressions-to-be-assigned.

For what it's worth, I think this would be useful enough to justify
its existence. Back in days of yore when dragons roamed the earth and
I wrote database-driven applications instead of hacking on the
database itself, I often wondered why I had to write two
completely-different looking SQL statements, one to insert the data
which a user had entered into a webform into the database, and another
to update previously-entered data. This feature would allow those
queries to be written in the same way, which would have pleased me,
back in the day.

I still do, and this would be a big help.  I don't care if it's non-standard.


.m

pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Allow superuser to grant passwordless connection rights onpostgres_fdw
Next
From: "Daniel Verite"
Date:
Subject: Re: ICU for global collation