Re: Promise index tuples for UPSERT
От | Anssi Kääriäinen |
---|---|
Тема | Re: Promise index tuples for UPSERT |
Дата | |
Msg-id | 1412763012.8545.127.camel@TTY32 обсуждение исходный текст |
Ответ на | Re: Promise index tuples for UPSERT (Peter Geoghegan <pg@heroku.com>) |
Список | pgsql-hackers |
On Wed, 2014-10-08 at 01:10 -0700, Peter Geoghegan wrote: > On Wed, Oct 8, 2014 at 12:41 AM, Anssi Kääriäinen > <anssi.kaariainen@thl.fi> wrote: > > The MySQL documentation says that "you should try to avoid using an ON > > DUPLICATE KEY UPDATE clause on tables with multiple unique indexes"[1]. > > The proposed feature's documentation has the same suggestion[2]. Still, > > the feature defaults to this behavior. Why is the default something the > > documentation says you shouldn't do? > As we all know, naming a unique index in DML is ugly, and has poor > support in ORMs. It seems likely that we're better off making it > optional - it hasn't been much of a problem with the existing subxact > looping pattern. The subxact approach is a bit different than the proposed UPSERT command. It loops: try: INSERT INTO author VALUE('Jack', 'tom@example.com', 34) except UniqueConstraintViolation: UPDATE authorSET ... WHERE name = 'Jack' while the UPSERT command does something like: try: INSERT INTO author VALUE('Jack', 'tom@example.com', 34) except UniqueConstaintViolation: UPDATE authorSET ... WHERE name = 'Jack' OR email = 'tom@example.com' LIMIT 1; - Anssi
В списке pgsql-hackers по дате отправления: