1. Using PostgreSQL, can a foreign key reference the table it appears in? Or is there some other way to do this? !coderpony #

    Tuesday, 08-May-12 01:48:17 UTC from web
    1. @toksyuryel Isn't a foreign key _by definition_ a reference to another table's primary key?

      Tuesday, 08-May-12 01:49:41 UTC from web
      1. @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.

        Tuesday, 08-May-12 01:56:42 UTC from web
        1. @toksyuryel *posts row, in both instances

          Tuesday, 08-May-12 01:58:53 UTC from web
        2. @toksyuryel Not too sure on whether PostgreSQL has such a feature, but maybe you can set that as a value constraint somehow?

          Tuesday, 08-May-12 01:59:11 UTC from web
          1. @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?)

            Tuesday, 08-May-12 02:04:40 UTC from web