Re: Help with array constraints
От | Jason Hihn |
---|---|
Тема | Re: Help with array constraints |
Дата | |
Msg-id | NGBBLHANMLKMHPDGJGAPGEGOCGAA.jhihn@paytimepayroll.com обсуждение исходный текст |
Ответ на | Re: Help with array constraints ("Nigel J. Andrews" <nandrews@investsystems.co.uk>) |
Ответы |
Re: Help with array constraints
|
Список | pgsql-general |
> -----Original Message----- > From: pgsql-general-owner@postgresql.org > [mailto:pgsql-general-owner@postgresql.org]On Behalf Of Nigel J. Andrews > Sent: Thursday, April 03, 2003 11:19 AM > To: Jason Hihn > Cc: Richard Huxton; pgsql-general@postgresql.org > Subject: Re: [GENERAL] Help with array constraints > > > On Thu, 3 Apr 2003, Jason Hihn wrote: > You probably want to write your own function(s) and install it(them) as > trigger(s). > > create function letter_fk () returns trigger as ' > declare > ind integer; > begin > for ind in array_dims(NEW.letters) loop > perform 1 from _test where id = NEW.letters[ind]; > if not found then > raise exception ''My foriegn key constraint > violation''; > end if; > end loop; > > return NEW; > end; > ' as language 'plpgsql'; > > create trigger my_array_fkey > before insert > on test > for each row execute procedure letter_fk(); > > > Or something like that anyway. Also that's only a start. Ah that's more like what I'm looking for. I have to attempt a select of the new letter in the contrainted-to table. If it finds it, success! If the contrainted-to table has an index, it should be very fast no matter how many letters it's being constrained against... "SELECT NEW.letter FROM constraint_table WHERE letter=id" if null set raise exception. I would have thought this would be built in? Can it be?
В списке pgsql-general по дате отправления: