pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pankaj Jangid <pankaj.jangid@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: How to represent a bi-directional list in db?
Date: Sun, 22 Sep 2019 19:55:00 +0530
Message-ID: <m2muew8l37.fsf@gmail.com> (raw)


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





view thread (7+ messages)  latest in thread

Message-ID: <m2muew8l37.fsf@gmail.com>
Permalink:  ../m2muew8l37.fsf@gmail.com/
Also on:    postgresql.org/message-id/m2muew8l37.fsf@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: pankaj.jangid@gmail.com
  Subject: Re: How to represent a bi-directional list in db?
  In-Reply-To: <m2muew8l37.fsf@gmail.com>
  References: <m2muew8l37.fsf@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox