I have a simple table like this :
CREATE TABLE gateway_text ( id BIGSERIAL NOT NULL PRIMARY KEY, text TEXT NOT NULL, hash char(40) UNIQUE, created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT now() NOT NULL ); CREATE RULE "gateway_text_on_duplicate_ignore" AS ON INSERT TO "gateway_text" WHERE EXISTS(SELECT 1 FROM gateway_text WHERE hash=NEW.hash) DO INSTEAD SELECT * FROM gateway_text WHERE hash=NEW.hash;
As you can see, the rule is for when the first select is passed (the hash is already in database) so the first insert, is not the one DO INSTEAD supposed to run for. But the problem is, every time I run insert, I get the select result, even for the first insert of a hash. In my case this is OK, very OK actually, but I don't know if this is correct or this is a bug? can I simply accept this as normal and relay on this?