I have two tables:
CREATE TABLE est (
est_id serial PRIMARY KEY
, est_nom varchar(70)
);
CREATE TABLE bm (
id serial PRIMARY KEY
, est_nom int
, nom varchar(70)
, CONSTRAINT FK_bm_est FOREIGN KEY(est_nom) REFERENCES est(est_id) ON DELETE SET NULL
);
I want to insert this data in bmbm
INSERT INTO bm
VALUES
(netx serial,'DAPR','leopold stotch'),
(netx serial,'LDGA','fredderik gauss'),
(netx serial,'SDCD','edward gortz')
butInput values in column 2 are strings, estcorresponding to est.est_nom
. They are not intI need the matching est.est_id
instead.
I want to get existing values from est.est_nom
and use them for the insert into bm.est_id
.
If not found, first insert new rows in est
and use the resulting serial est_nom
for the insert into bm
.