Re: "reverse" (?) UPSERT -- how to ?

2024-02-17 Thread Karsten Hilbert
Am Sat, Feb 17, 2024 at 07:25:11PM +0100 schrieb Karsten Hilbert: > +1 except that I've got use for both parts of the UNION on > their own (they are both views themselves involving a bunch > of joins with yet other tables, 4 or 5 each or so ;-) Just for kicks, attached find the SQL change script

Re: "reverse" (?) UPSERT -- how to ?

2024-02-17 Thread Karsten Hilbert
Am Sat, Feb 17, 2024 at 11:54:05AM -0500 schrieb Greg Sabino Mullane: > > There will be a view giving rows for > > each detail row enriched with master table data > > UNION ALL > > rows for each master row that does not have any detail row with > > detail table colu

Re: "reverse" (?) UPSERT -- how to ?

2024-02-17 Thread Karsten Hilbert
Am Sat, Feb 17, 2024 at 09:33:11AM -0700 schrieb Rob Sargent: > > So, is this doable within one SQL statement (short of > > creating and running the abovementioned function in > > one go ;-) ? > > > > Perhaps your pk_detail can be defined as generated always identity? Rob, I'm sure there's someth

Re: "reverse" (?) UPSERT -- how to ?

2024-02-17 Thread Karsten Hilbert
Am Sat, Feb 17, 2024 at 08:55:57AM -0800 schrieb Adrian Klaver: > >Dear list members, > > > > >So, is this doable within one SQL statement (short of > >creating and running the abovementioned function in > >one go ;-) ? > > Don't know what version of Postgres you are on, assuming 15+ then maybe?:

Re: "reverse" (?) UPSERT -- how to ?

2024-02-17 Thread Adrian Klaver
On 2/17/24 07:24, Karsten Hilbert wrote: Dear list members, So, is this doable within one SQL statement (short of creating and running the abovementioned function in one go ;-) ? Don't know what version of Postgres you are on, assuming 15+ then maybe?: MERGE https://www.postgresql.org/doc

Re: "reverse" (?) UPSERT -- how to ?

2024-02-17 Thread Greg Sabino Mullane
On Sat, Feb 17, 2024 at 10:24 AM Karsten Hilbert wrote: > There will be a view giving rows for > each detail row enriched with master table data > UNION ALL > rows for each master row that does not have any detail row with > detail table columns NULLed > A better

Re: "reverse" (?) UPSERT -- how to ?

2024-02-17 Thread Rob Sargent
> On Feb 17, 2024, at 8:24 AM, Karsten Hilbert wrote: > > Dear list members, > > maybe I am overlooking something. > > PostgreSQL offers UPSERT functionality by way of > >INSERT INTO ... ON CONFLICT ... DO UPDATE ...; > > Consider this pseudo-code schema > >table master >

"reverse" (?) UPSERT -- how to ?

2024-02-17 Thread Karsten Hilbert
Dear list members, maybe I am overlooking something. PostgreSQL offers UPSERT functionality by way of INSERT INTO ... ON CONFLICT ... DO UPDATE ...; Consider this pseudo-code schema table master pk_master serial primary key value text ;