Re: Insert works but fails for merge
От | Greg Sabino Mullane |
---|---|
Тема | Re: Insert works but fails for merge |
Дата | |
Msg-id | CAKAnmm+UgOUpGeurzeFg6r-q7RwhwuY-rQLd2nhSMk2sFfTJQA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Insert works but fails for merge (Adrian Klaver <adrian.klaver@aklaver.com>) |
Ответы |
Re: Insert works but fails for merge
|
Список | pgsql-general |
So it looks like the OP does not mind updating more than one row. If you want to keep it simple and not do a lot of casting, consider using a CTE to do a reverse-upsert and use a prepared statement. Prepare and cast once, and have your app send the raw uncasted strings many, many times:
prepare foo(text,int,timestamptz) as with x as (update tab1 set mid=$2 where id=$1 returning 1)
insert into tab1 select $1,$2,$3 where not exists (select 1 from x);
execute foo('5efd4c91-ef93-4477-840c-a723ae212d99', 123, '2024-08-09T11:33:49.402585600Z');
execute foo('some_other_id', 456, '2024-08-11T21:44:55.8675309Z');
etc.
Your app/driver may or may not already do protocol-level statement prepare/execute automagically, so test that way first.
It's version 15.4 postgres.
Keep on the latest revision. Right now, that's 15.8. Upgrading revisions is quick and painless.
Cheers,
Greg
В списке pgsql-general по дате отправления: