How to represent a bi-directional list in db? - Mailing list pgsql-general

From Pankaj Jangid
Subject How to represent a bi-directional list in db?
Date
Msg-id m2muew8l37.fsf@gmail.com
Whole thread Raw
Responses Re: How to represent a bi-directional list in db?
List pgsql-general
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



pgsql-general by date:

Previous
From: Arup Rakshit
Date:
Subject: Re: Extend inner join to fetch not yet connected rows also
Next
From: Francisco Olarte
Date:
Subject: Re: How to represent a bi-directional list in db?