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

2021-07-13 Thread Laurenz Albe
On Tue, 2021-07-13 at 10:00 -0400, David Gauthier wrote: > 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. This won't work, and it is broken by design. Change your data model to adhere to the first normal form,

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

2021-07-13 Thread Ken Tanzer
On Tue, Jul 13, 2021 at 7:47 AM David Gauthier wrote: > Ok, thanks. > > I was looking for, but didn't find, something like... > each_element_of(regexp_split_to_array(children_csv)) references > projects(project); > Of course the "each_element_of" is my creation here :-) > > Several years ago, I

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

2021-07-13 Thread David Gauthier
Ok, thanks. I was looking for, but didn't find, something like... each_element_of(regexp_split_to_array(children_csv)) references projects(project); Of course the "each_element_of" is my creation here :-) On Tue, Jul 13, 2021 at 10:07 AM David G. Johnston < david.g.johns...@gmail.com> wrote: >

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

2021-07-13 Thread David G. Johnston
On Tuesday, July 13, 2021, David Gauthier wrote: > > > 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. > > You cannot use a check constraint here as the behavior is not immutable. You can use a

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

2021-07-13 Thread David Gauthier
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),