Conversation
Notices
-
Using PostgreSQL, can a foreign key reference the table it appears in? Or is there some other way to do this? !coderpony #SQL
Tuesday, 08-May-12 01:48:17 UTC from web-
@toksyuryel Isn't a foreign key _by definition_ a reference to another table's primary key?
-
@bitshift Essentially, but I was wondering if there was a way to do the same thing within the same table. The specific use case here is to guarantee that the replyto column of a post row actually matches the id column of an existing post row.
-
@toksyuryel *posts row, in both instances
-
@toksyuryel Not too sure on whether PostgreSQL has such a feature, but maybe you can set that as a value constraint somehow?
-
@bitshift Certainly could, though I'd rather not. Maybe I could just work around it by referencing the post id in the conversations table (which references the posts table. Circular references ftw?)
-