Right, now your intent is clearer. A common solution to this is to turn the relationships around:
Code:
create table comments (comment_id integer primary key,
comment_text varchar(...));
create table images (image_id integer primary key,
comment_id references comments);
create table posts (post_id integer primary key,
comment_id references comments);
Or you could use a supertype/subtype model, with the comments held in the supertype:
Code:
create table objects (object_id integer primary key, object_type varchar(10),
comment_text varchar(...),
constraint obj_uk unique (object_id, object_type)
);
create table images (object_id integer primary key, object_type varchar(10),
constraint image_object_fk foreign key(object_id, object_type)
references objects
constraint image_type_chk check (object_type = 'IMAGE')
);
... etc.
Note the use of a "superkey" obj_uk in the supertype to ensure via the foreign keys that each object is only of one type.