0

Hi I have the following schema in my app.

-- Table: Investment_round
CREATE TABLE Investment_round (
    id serial  NOT NULL,
    round_type varchar(50)  NOT NULL,
    money bigint  NOT NULL,
    Project_id int  NOT NULL,
    CONSTRAINT Investment_round_pk PRIMARY KEY (id)
);

-- Table: Investor
CREATE TABLE Investor (
    id serial  NOT NULL,
    name int  NOT NULL,
    url int  NULL,
    Investment_round_id int  NOT NULL,
    CONSTRAINT Investor_pk PRIMARY KEY (id)
);

-- Reference: Investment_round_startups_page (table: Investment_round)
ALTER TABLE Investment_round ADD CONSTRAINT Investment_round_startups_page
    FOREIGN KEY (Project_id)
    REFERENCES startups_page (angel_id)  
    NOT DEFERRABLE 
    INITIALLY IMMEDIATE
;

-- Reference: Investor_Investment_round (table: Investor)
ALTER TABLE Investor ADD CONSTRAINT Investor_Investment_round
    FOREIGN KEY (Investment_round_id)
    REFERENCES Investment_round (id)  
    NOT DEFERRABLE 
    INITIALLY IMMEDIATE
;

I'm a bit confused about optimal pipeline of inserting the data. Suppose that firstly I need to insert the data to Investment_round table. Then I need to insert the data to Investor table with corresponding Investment_round_id

It seems that the reasonable way is to store Investment_round_id and then to update Investor table. But how can I achieve that without making an external request?

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.