CREATE TABLE results ( id uuid primary key DEFAULT gen_random_uuid(), queryId uuid not null, documentId uuid not null, value TEXT not null, cleanVersion int not null, textVersion int not null, queryVersion int not null, foreign key (queryId) references queries(id), unique (queryId, documentId, cleanVersion, textVersion, queryVersion) );