It seems tedious, but I would create a table for each product in total.
CREATE TABLE foo (id uuid PRIMARY KEY); CREATE TABLE bar (id uuid PRIMARY KEY, s text NOT NULL); CREATE TABLE baz (id uuid PRIMARY KEY, a integer NOT NULL, b integer NOT NULL, c integer NOT NULL);
You probably want to save some metadata along with each type of record:
CREATE TABLE envelope (id uuid PRIMARY KEY, t timestamptz NOT NULL DEFAULT now(), by text NOT NULL DEFAULT sessions_user);
And this involves limiting the foreign key:
CREATE TABLE foo (id uuid PRIMARY KEY REFERENCES envelope); CREATE TABLE bar (id uuid PRIMARY KEY REFERENCES envelope, s text NOT NULL); CREATE TABLE baz (id uuid PRIMARY KEY REFERENCES envelope, a integer NOT NULL, b integer NOT NULL, c integer NOT NULL);
And if you are even more strict, you can imagine the storage of the ty column with the type name and its use to build a complex foreign key. (As described in “Where Not to Use Table Inheritance” on the LedgerSMB blog.)
source share