'one-to-many' relation integrity issue for time ranges
问题 Suppose I have table like: CREATE TABLE foo ( id SERIAL PRIMARY KEY , barid integer NOT NULL REFERENCES bar(id) , bazid integer NOT NULL REFERENCES baz(id) , startdate timestamp(0) NOT NULL , enddate timestamp(0) NOT NULL ); The purpose for that table is to provide a pseudo 'one-to-many' relation between tables bar and baz, but the relation can change through time: SELECT * FROM bar JOIN foo on TRUE AND foo.barid = bar.id AND now() BETWEEN foo.startdate AND foo.enddate JOIN baz on baz.id =