The error you get is on line 3. i.e. she is not in
CONSTRAINT no_duplicate_tag UNIQUE (question_id, tag_id)
but earlier:
CREATE TABLE tags ( (question_id, tag_id) NOT NULL,
I have absolutely no idea why you put it - what is the purpose? What is the logic?
Anyway. A proper table definition is similar to a sawtooth.
And if you want to add a unique tag tag1, tag2, tag3 (which sounds very suspicious), then the syntax:
CREATE TABLE tags ( question_id INTEGER NOT NULL, tag_id SERIAL NOT NULL, tag1 VARCHAR(20), tag2 VARCHAR(20), tag3 VARCHAR(20), PRIMARY KEY(question_id, tag_id), UNIQUE (tag1, tag2, tag3) );
or, if you want to have a restriction specified in accordance with your desire:
CREATE TABLE tags ( question_id INTEGER NOT NULL, tag_id SERIAL NOT NULL, tag1 VARCHAR(20), tag2 VARCHAR(20), tag3 VARCHAR(20), PRIMARY KEY(question_id, tag_id), CONSTRAINT some_name UNIQUE (tag1, tag2, tag3) );
user80168 Aug 17 '09 at 9:58 2009-08-17 09:58
source share