Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 456 Bytes

inheritance.md

File metadata and controls

18 lines (14 loc) · 456 Bytes

Postgres Inheritance

CREATE TABLE IF NOT EXISTS invoices (
	invoice_number int NOT NULL PRIMARY KEY,
	issued_on date NOT NULL DEFAULT now()
);

CREATE TABLE IF NOT EXISTS government_invoices (
	department_id text NOT NULL
) INHERITS (invoices);

INSERT INTO invoices (invoice_number) VALUES (100);
INSERT INTO government_invoices(invoice_number, department_id) VALUES (101, 'DOD');

SELECT * FROM invoices;
SELECT * FROM government_invoices;