Just curious, if I have this table:
CREATE TABLE "post" ( "id" SERIAL, "revision" INTEGER NOT NULL DEFAULT 0, "summary" CHARACTER VARYING NOT NULL, "description" TEXT NOT NULL, "user_id" INTEGER NOT NULL REFERENCES "user" ("id") MATCH FULL ON UPDATE CASCADE ON DELETE RESTRICT, "post_type_id" INTEGER NOT NULL REFERENCES "post_type" ("id") MATCH FULL ON UPDATE CASCADE ON DELETE RESTRICT, "ctime" TIMESTAMP WITH TIME ZONE DEFAULT NOW(), PRIMARY KEY("id", "revision") ); to store posts, and this table:
CREATE TABLE "post_state" ( "post_id" INTEGER NOT NULL, "assembly_seat_id" INTEGER NOT NULL REFERENCES "assembly_seat" ("id") MATCH FULL ON UPDATE CASCADE ON DELETE RESTRICT, PRIMARY KEY("post_id") ); and I want my post_id field to point to post(id), how do I do it? I have tried with the following phrase:
"post_id" INTEGER NOT NULL UNIQUE, REFERENCES "post" ("id") MATCH SIMPLE ON UPDATE RESTRICT ON DELETE RESTRICT, but I am getting this error:
ERROR: there is no unique constraint matching given keys for referenced table "post"
The values of post_state(asembly_seat_id) do not change in this case.
post_idis not unique (only the post_id/revision combination is unique), you can't reference it.