I'm trying to have a linked list-like (not actually, it's supposed to be a tree structure) in my database, and have a PostgresSQL CHECK that prevents cycles.
My data structure consists of records in a (id, parent_id, other_things)
format. Is it possible to do this with a CHECK?
Edit: schema clarification My schema is as follows:
CREATE TABLE static_pages (
id SERIAL PRIMARY KEY,
parent_id INTEGER REFERENCES static_pages(id),
other_things
);
And contains tuples like
(1, NULL),
(2, NULL),
(3, 1),
(4, 3),
(5, NULL)
et cetera.