Sample Header Ad - 728x90

How to INSERT a new record into 2 tables with FKEY inheritance?

-1 votes
1 answer
64 views
Inheritance has been setup with FKEY instead of INHERITS due to FKEY limitation. My question: How to INSERT a new record into bonds table?
CREATE TABLE IF NOT EXISTS instruments (
  id SERIAL,
  created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
  ticker varchar(255),
  type varchar(255),
  PRIMARY KEY (id)
);
  
CREATE TABLE IF NOT EXISTS bonds (
  id int NOT NULL,
  maturity date,
  PRIMARY KEY (id),
  CONSTRAINT fk_instruments FOREIGN KEY (id) REFERENCES instruments(id)
);

CREATE TABLE IF NOT EXISTS equities (
  id int NOT NULL,
  name varchar(255),
  PRIMARY KEY (id),
  CONSTRAINT fk_instruments FOREIGN KEY (id) REFERENCES instruments(id)
);
Asked by John Doe (1 rep)
Sep 12, 2024, 08:21 AM
Last activity: Sep 15, 2024, 12:39 AM