How do you ensure that a field's values reference an existing table's name in a schema? For example, in the following, how would I get the properties
field in the item
table to effectively make an ELEMENT REFERENCES
on the table names in the property
schema?
(Note: I believe ELEMENT REFERENCES
is only going to be available in Postgres 9.6 or later, so I would create a item_property
'join' table.)
CREATE SCHEMA property;
CREATE TABLE item (
id SERIAL4 PRIMARY KEY,
name TEXT NOT NULL,
-- e.g. iPhone, hamburger
properties TEXT[] NOT NULL
-- e.g. {'property_taste'}
);
CREATE TABLE property.taste (
item_id INT4 REFERENCES item PRIMARY KEY,
description TEXT NOT NULL
-- e.g. sweet, sour, salty, savory
);
CREATE TABLE property.processor (
item_id INT4 REFERENCES item PRIMARY KEY,
num_cores INT2 NOT NULL,
-- e.g. 4
freq_mhz INT2 NOT NULL
-- e.g. 1600
);