0

I have a table that store words demo sentence, and I have a scrapy process to fetch new demo sentence and store into database. Now I do not want to insert into duplicate sentence. So I want if the new sentence was having greater 90% similiar records in database, then refuse to insert into. Is it possible to add this custom constraint? This is my database DDL:

CREATE TABLE public.sentence (
    id int8 NOT NULL GENERATED ALWAYS AS IDENTITY,
    word_id int8 NOT NULL,
    sentence_en varchar NOT NULL,
    sentence_zh varchar NOT NULL,
    created_time int8 NOT NULL,
    updated_time int8 NOT NULL,
    word varchar NOT NULL,
    CONSTRAINT sentence_pkey PRIMARY KEY (id)
);
CREATE INDEX index_dict_word_id ON public.sentence USING btree (word_id);

this sentence_en column was the one that I want to constraint.

2
  • Are you able to write a function which returns true if the two inputs are considered similar?
    – guettli
    Dec 3 '21 at 7:41
  • I have write a function right now, but I still want to make sure from the database.@guettli maybe using a trigger
    – Dolphin
    Dec 3 '21 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.