Re: The problem is related to concurrent resquests

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: The problem is related to concurrent resquests
Дата
Msg-id A737B7A37273E048B164557ADEF4A58B53852FE7@ntex2010i.host.magwien.gv.at
обсуждение исходный текст
Ответ на Re: The problem is related to concurrent resquests  (Nguyen Hoai Nam <namptit307@gmail.com>)
Список pgsql-admin
Nguyen Hoai Nam wrote:
> In fact, in mysql, trigger can detect this case. But when I apply this method to Postgresql, it's not
> ok. Do you know why?

I cannot tell you about MySQL, but if you insert two rows at the same time
in PostgreSQL, the SQL queries run from the trigger can run concurrently.
None of them will see the row of the other insert, because this will become
only visible when the transaction (which includes the execution trigger)
has completed.

> I will follow your suggestion. However imaging we add a "network_id" column (it contain the id of
> network)  to "subnet" tables.. so I need to do what to prevent a record with overlap CIDR and same
> network_id.?

There is no need to add a new column, just add a constraint.

If the table was defined with a varchar column like this:

   CREATE TABLE network (id integer PRIMARY KEY, subnet varchar(30) NOT NULL);

Add the following constraint:

   ALTER TABLE network ADD CONSTRAINT network_subnet_excl EXCLUDE USING gist ((subnet::cidr) inet_ops WITH &&);

Then you are done.

Yours,
Laurenz Albe


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

Предыдущее
От: Nguyen Hoai Nam
Дата:
Сообщение: Re: The problem is related to concurrent resquests
Следующее
От: oded
Дата:
Сообщение: Connection refused error message after ip change