Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iC2nY-000376-T2 for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 14:25:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iC2nW-0008Ax-Sl for pgsql-general@arkaria.postgresql.org; Sun, 22 Sep 2019 14:25:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iC2nW-0008Ai-EH for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 14:25:10 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iC2nS-0000XW-PO for pgsql-general@lists.postgresql.org; Sun, 22 Sep 2019 14:25:09 +0000 Received: by mail-pf1-x435.google.com with SMTP id b128so7395558pfa.1 for ; Sun, 22 Sep 2019 07:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:organization:date:message-id:user-agent :mime-version; bh=+0KUz/aHHuUyOo6TgQwHNIr/I1b6dJR7y1UxqV1DTWU=; b=GVQiYKdUcCOHJvkoBkeChKwe1aZvcm/AXLhlz+Td7iJMjb5O7K9FrGFa9y/JmThoWC 1MgekYFn1MXYyl4bKyjhH9+As9nrtvSJRoNj7F5ziSrSv0B3Y5ZTGxJ3Q+G6f0aSr+uM suIRT++PO+awVaZYOrKuXw3SjTKj/ClGDbfaTOzIYjsSf4AlbMFbW5oesI7cT3rtZu1x XWKWXd1eKpGbxs0t2Tdk/SpkuzQoRNbt2eyca4aW4WaxbiGQHCzuGAdcSGNQIdxIZEVP mke6iWsEQ3IS/7Qew12iBSuQ0xQ81X1Sh9CWemp1pLbijT3+HpESOtGTFr+zJ+XKSXM7 Sz2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:organization:date:message-id :user-agent:mime-version; bh=+0KUz/aHHuUyOo6TgQwHNIr/I1b6dJR7y1UxqV1DTWU=; b=S/uhRARIT/xDfSCGR6iK85enAgRdLWv4bCqezGng855PNOVloZIwN97XUaxeE6FmlT og4xBJkHxS7d88gWGQ/7lfL/TvRcaU5IbibyywbNYLgfE7rwhMq86A3HDORC+T3mPu1O w1v+FhImfjJNIehU/Czk5HYrMiUQr2OhxJeeQbgTiZYTTga/O6F6P+L2Tev3bcOhm5rk vuiTMRHNGsjMmXxJw5APu3+pj1UrU7GTZUyBydONEaTy9Ma+Hkx1B2xVKGq7u/m4VQ5X Z2YCuEdTazPMmwFjDuxRmyDMKDF1/Kc9PqqKUFdQmgI/c9uRUJZOtHLwlPGkN0jumeR6 p8cA== X-Gm-Message-State: APjAAAXRdX5CSM+rZb3uSt/4W2PtK0A/9BzyZqB1CL4feF1loQ2aSGzR 8tV2jdBZfM1BmVKt4ShEmDek/2Q= X-Google-Smtp-Source: APXvYqwEEFx5IM4oHfnekmwVUH3xrHaHUvMnmXHwjkdxhkA6EfOFxbIVXxglF6OgzdkCq4iD+kwopQ== X-Received: by 2002:a17:90a:d98a:: with SMTP id d10mr1025921pjv.65.1569162304961; Sun, 22 Sep 2019 07:25:04 -0700 (PDT) Received: from Pankajs-MacBook-Pro.local ([49.36.128.80]) by smtp.gmail.com with ESMTPSA id n9sm7791060pgf.64.2019.09.22.07.25.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Sep 2019 07:25:03 -0700 (PDT) Received: by Pankajs-MacBook-Pro.local (Postfix, from userid 501) id 8B233203904DA2; Sun, 22 Sep 2019 19:55:00 +0530 (IST) From: Pankaj Jangid To: pgsql-general@lists.postgresql.org Subject: How to represent a bi-directional list in db? Organization: Code is Great! Date: Sun, 22 Sep 2019 19:55:00 +0530 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (darwin) MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I am creating an application for a manufacturing scenario. To represent stages in an assembly line, I wanted to create following table, CREATE TABLE stages ( id SERIAL PRIMARY KEY, name VARCHAR(80) NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, prev_stage_id SERIAL REFERENCES stages NULL, next_stage_id SERIAL REFERENCES stages NULL, process_id SERIAL REFERENCES processes NOT NULL ); But it: Failed with: conflicting NULL/NOT NULL declarations for column "prev_stage_id" of table "stages" Is it not possible to create "nullable" self referencing foreign keys? -- Pankaj Jangid