[GENERAL] upsert: is there a shortcut? - Mailing list pgsql-general

From Daniele Varrazzo
Subject [GENERAL] upsert: is there a shortcut?
Date
Msg-id CA+mi_8Zb8QCBT_c2ntzt_VwgCf5xiZOJi6Y_D_YZ0DqhDqS=LQ@mail.gmail.com
Whole thread Raw
Responses Re: [GENERAL] upsert: is there a shortcut?
List pgsql-general
Hello,

it seems not, but I feel like asking.

Is there a way to express a statement like "if you have a conflict on
insert replace all the values in the conflicting record" without
specifying all the fields explicitly? I.e. in a replication system
(where occasional accidents mean replication may restart slightly
before what's already on the target) I generate statements like:

insert into "order_log" ("id","cr_date","order_id","message")
    values (%s, %s, %s, %s)
    on conflict ("id") do update
    set ("cr_date","order_id","message") =
        (excluded."cr_date",excluded."order_id",excluded."message")

Is there a way to avoid replicating the list of fields and use instead
something like (new.*) = (excluded.*) as one could do in a trigger?
(that would also imply an (id = excluded.id but it seems harmless).

It seems to me an use case common enough that some syntactic help...
would help. "do update *"? "do update (target.*) = (excluded.*)"?


-- Daniele


pgsql-general by date:

Previous
From: vinny
Date:
Subject: Re: [GENERAL] Row based permissions: at DB or at Application level?
Next
From: Vincenzo Romano
Date:
Subject: [GENERAL] RETURNS SETOF RECORD with 1 column