Need to check each element of an array satisfies a foreign key constraint

Поиск
Список
Период
Сортировка
От David Gauthier
Тема Need to check each element of an array satisfies a foreign key constraint
Дата
Msg-id CAMBRECBOOybGgVKHe_E6MYqY7VJ-rS4YME8SwpK5+baAg3cRgg@mail.gmail.com
обсуждение исходный текст
Ответы Re: Need to check each element of an array satisfies a foreign key constraint  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Need to check each element of an array satisfies a foreign key constraint  (Laurenz Albe <laurenz.albe@cybertec.at>)
Список pgsql-general
Hi:

I have a column in a table which is a csv of values and I need to make sure each element of the csv = the PK of that same table.

create table projects (
  project varchar primary key,
  children_csv varchar );

insert into projects (project,children_csv) values 
('prj1',null),
('prj2',null),
('prj3','prj1,prj2');

I need to make sure that the elements of 'prj1,prj2' are both valid projects.

I'm thinking the csv should be split into an array (regexp_split_to_array) but the constraint needs to somehow iterate over each element to check that they are all valid.  

I suppose I could write a stored procedure to do this and call it in a check constraint. But I was wondering if there is something more elegant.

Thanks in Advance ! 

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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: pg_wal lifecycle
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Need to check each element of an array satisfies a foreign key constraint