Re: mysql replace in postgreSQL?

Поиск
Список
Период
Сортировка
От Lincoln Yeoh
Тема Re: mysql replace in postgreSQL?
Дата
Msg-id 5.2.1.1.1.20051101001751.0358a550@localhost
обсуждение исходный текст
Ответ на Re: mysql replace in postgreSQL?  (David Fetter <david@fetter.org>)
Ответы Re: mysql replace in postgreSQL?  (Jan Wieck <JanWieck@Yahoo.com>)
Список pgsql-general
At 08:24 AM 10/30/2005 -0800, David Fetter wrote:

> > >http://developer.postgresql.org/docs/postgres/plpgsql-control-structure
> s.html#PLPGSQL-ERROR-TRAPPING
> >
> > Erm, doesn't it have the same race conditions?
>
>No, don't believe it does.  Have you found some?

Depends on how you do things.

As I mentioned, it's only fine if you have the relevant uniqueness constraint.

For example, if instead of:

CREATE TABLE db (a INT PRIMARY KEY, b TEXT);

You do:
CREATE TABLE db (a INT, b TEXT);

Then create the function as in the docs.

Then open up two psql sessions.

Session #1
begin;
SELECT merge_db(1, 'david');
select * from db;

Session #2
begin;
SELECT merge_db(1, 'dennis');
select * from db;

Then, do commit in both sessions.

You'll end up with duplicates.

What actually protected the data before was the uniqueness constraint due
to the primary key.

BUT, if you already have the uniqueness constraint, you won't have a
problem mis-inserting duplicates with any of the typical naive methods either.

Not saying the example in the docs is wrong, but it might be misleading to
people who don't fully understand it. That doesn't seem too far fetched to
me given that a fair number here have suggested the usual variations of
"select, update if exist insert if not" and assumed they will work.

Would those methods be fine in non MVCC databases?

Regards,
Link.


В списке pgsql-general по дате отправления:

Предыдущее
От: "Wes Williams"
Дата:
Сообщение: Re: Oracle 10g Express - any danger for Postgres?
Следующее
От: Lincoln Yeoh
Дата:
Сообщение: Re: Please HELP - URGENT - transaction wraparound