I'm trying to set automaticaly an updatedAt field on postgres
Here my dump file:
CREATE TABLE IF NOT EXISTS "Product" (
"id" uuid PRIMARY KEY,
"createdAt" timestamp(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP),
"updatedAt" timestamp(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP),
"name" TEXT NOT NUll UNIQUE,
"type" "ProductType" NOT NULL
);
CREATE RULE set_updatedAt AS ON UPDATE TO "Product"
DO UPDATE "Product" SET "updatedAt" = NOW() WHERE NEW.id = OLD.id AND NEW."updatedAt" = OLD."updatedAt";
On UPDATE, I'm receiving the error "infinite recursion detected in rules for relation "Product""
I do not understand how it's possible whith this kind of condition "NEW.id = OLD.id AND NEW."updatedAt" = OLD."updatedAt""
Any idea, how can I perform a treatment like that?
version : postgres 10
Thanks