BEGIN; CREATE TABLE examples ( -- name type constraints id BIGSERIAL PRIMARY KEY ); CREATE TABLE example_texts ( -- name type constraints id BIGSERIAL PRIMARY KEY, example_id BIGINT NOT NULL REFERENCES examples (id), language_id BIGINT NOT NULL REFERENCES languages (id), index BIGINT NOT NULL, value TEXT NOT NULL, -- CONSTRAINT name CHECK (condition) CONSTRAINT index_is_not_negative CHECK (index >= 0), CONSTRAINT value_is_sane_text CHECK (is_sane_text(value)) ); CREATE UNIQUE INDEX example_texts_example_language_index ON example_texts (example_id, language_id, index); COMMIT;