Skip to main content
Clarify
Source Link
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

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.

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 bm

INSERT INTO bm
VALUES
(netx serial,'DAPR','leopold stotch'),
(netx serial,'LDGA','fredderik gauss'),
(netx serial,'SDCD','edward gortz')

but in column 2, est. They are not int.

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.

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 bm

INSERT INTO bm
VALUES
(netx serial,'DAPR','leopold stotch'),
(netx serial,'LDGA','fredderik gauss'),
(netx serial,'SDCD','edward gortz')

Input values in column 2 are strings, corresponding to est.est_nom. I 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.

format, tags, translate text
Source Link
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

I have two tables:

est
est_idSERIAL PK
est_nomVARCHAR(70)
bm
idSERIAL PK
est_nomINT
nomVARCHAR(70)
CONSTRAINT FK_bm_est FOREIGN KEY(est_nom)
REFERENCES est(est_id)
ON DELETE SET NULL
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 bm

INSERT INTO bm
VALUES
(netx serial,'DAPR','leopold stotch'),
(netx serial,'LDGA','fredderik gauss'),
(netx serial,'SDCD','edward gortz')

but in column 2, est. They are not int.

I want to look for thoseget existing values in the est table in the est_nom column and if it finds it, give me its est_idfrom est.est_nom and use them for the insert it in bm.est_idinto bm.est_id.

If it doesn't find itnot found, first insert that data in the est tablenew rows in the est_nom columnest and assign it a consecutiveuse the resulting serial number. Then now I inserted itest_nom for the insert into bm with its new serial numberbm.

I have two tables:

est
est_idSERIAL PK
est_nomVARCHAR(70)
bm
idSERIAL PK
est_nomINT
nomVARCHAR(70)
CONSTRAINT FK_bm_est FOREIGN KEY(est_nom)
REFERENCES est(est_id)
ON DELETE SET NULL

I want to insert this data in bm

INSERT INTO bm
VALUES
(netx serial,'DAPR','leopold stotch'),
(netx serial,'LDGA','fredderik gauss'),
(netx serial,'SDCD','edward gortz')

but in column 2, est. They are not int.

I want to look for those values in the est table in the est_nom column and if it finds it, give me its est_id and insert it in bm.est_id.

If it doesn't find it, insert that data in the est table in the est_nom column and assign it a consecutive serial number. Then now I inserted it into bm with its new serial number.

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 bm

INSERT INTO bm
VALUES
(netx serial,'DAPR','leopold stotch'),
(netx serial,'LDGA','fredderik gauss'),
(netx serial,'SDCD','edward gortz')

but in column 2, est. They are not int.

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.

added 37 characters in body
Source Link
Paul White
  • 90.3k
  • 30
  • 424
  • 663

Postgresql - Insert values and add values to foreign key

I have two tables:

tablle - bm id SERIAL PK, est_nom INT, nom VARCHAR(70) CONSTRAINT FK_bm_est FOREIGN KEY(est_nom) REFERENCES est(est_id) ON DELETE SET NULL

est
est_idSERIAL PK
est_nomVARCHAR(70)

table - est est_id SERIAL PK, est_nom VARCHAR(70)

bm
idSERIAL PK
est_nomINT
nomVARCHAR(70)
CONSTRAINT FK_bm_est FOREIGN KEY(est_nom)
REFERENCES est(est_id)
ON DELETE SET NULL

iI want to insert this data in bm INSERT INTO bm VALUES (netx serial,'DAPR','leopold stotch'), (netx serial,'LDGA','fredderik gauss'), (netx serial,'SDCD','edward gortz')

INSERT INTO bm
VALUES
(netx serial,'DAPR','leopold stotch'),
(netx serial,'LDGA','fredderik gauss'),
(netx serial,'SDCD','edward gortz')

but in column 2, est. They are not int. I

I want to look for those values in the est table in the est_nom column and if it finds it, give me its est_id. and insert it in bm.est_id And if.

If it doesn't find it, insert that data in the est table in the est_nom column and assign it a consecutive serial number. Then now I inserted it into bm with its new serial number.

Postgresql - Insert values and add values to foreign key

I have two tables

tablle - bm id SERIAL PK, est_nom INT, nom VARCHAR(70) CONSTRAINT FK_bm_est FOREIGN KEY(est_nom) REFERENCES est(est_id) ON DELETE SET NULL

table - est est_id SERIAL PK, est_nom VARCHAR(70)

i want to insert this data in bm INSERT INTO bm VALUES (netx serial,'DAPR','leopold stotch'), (netx serial,'LDGA','fredderik gauss'), (netx serial,'SDCD','edward gortz')

but in column 2, est. They are not int. I want to look for those values in the est table in the est_nom column and if it finds it, give me its est_id. and insert it in bm.est_id And if it doesn't find it, insert that data in the est table in the est_nom column and assign it a consecutive serial number. Then now I inserted it into bm with its new serial number.

Insert values and add values to foreign key

I have two tables:

est
est_idSERIAL PK
est_nomVARCHAR(70)
bm
idSERIAL PK
est_nomINT
nomVARCHAR(70)
CONSTRAINT FK_bm_est FOREIGN KEY(est_nom)
REFERENCES est(est_id)
ON DELETE SET NULL

I want to insert this data in bm

INSERT INTO bm
VALUES
(netx serial,'DAPR','leopold stotch'),
(netx serial,'LDGA','fredderik gauss'),
(netx serial,'SDCD','edward gortz')

but in column 2, est. They are not int.

I want to look for those values in the est table in the est_nom column and if it finds it, give me its est_id and insert it in bm.est_id.

If it doesn't find it, insert that data in the est table in the est_nom column and assign it a consecutive serial number. Then now I inserted it into bm with its new serial number.

Source Link
Loading