Constraint doesn't see a currently insertet record

Поиск
Список
Период
Сортировка
От KÖPFERL Robert
Тема Constraint doesn't see a currently insertet record
Дата
Msg-id ED4E30DD9C43D5118DFB00508BBBA76EB165BE@neptun.sonorys.at
обсуждение исходный текст
Ответы Re: Constraint doesn't see a currently insertet record  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-sql
Hi,

yes that's my problem.
I've got a table and I put lots of contraints on it so that data stays
consistent. One constraint calls a fcn to do some kind of count() over that
table but it omits the 'to be inserted record'. What to do?

concrete problem:
Suppose a table i | tel | status | .....| \d+ | 1-7    | ...
status can be active, deleted or some more values
There may be not two rows where tel is equal and status is not deleted.
Other: As long as status=deleted there may be duplicate tel columns.

How would I make that sure?


My try was to create a check constraint like
("status" = 7) OR (("status" <> 7) AND (num_of_equal_tel_status_not_7("tel")
<= 1))

where num_of_equal_tel_status_not_7 is:
SELECT count(*) FROM "this table" WHERE "tel"=$1 AND "status"<>7

Note: status=7 means deleted


This works well until two recoreds are inserted which are status<>7.
The second gets inserted because the new record is not yet visible.


Another Idea was to make a trigger. But BTW how do I access a trigger
parameter if my trigger function must not have any parameter??????????

Ideas?



Tahks for any


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

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: postgres 8 data directory other then default?
Следующее
От: "Joel Fradkin"
Дата:
Сообщение: Re: postgres 8 data directory other then default?