What is the optimal pipeline for updating table on FK value in Postgresql?How do I insert a row which...
multiple null checks in Java8
Is there a way to pause a running process on Linux systems and resume later?
Why is Shelob considered evil?
Is it possible to detect 100% of SQLi with a simple regex?
Will linear voltage regulator step up current?
How to achieve physical gender equality?
Buying a "Used" Router
How can a kingdom keep the secret of a missing monarch from the public?
Is Apex Sometimes Case Sensitive?
Stream.findFirst different than Optional.of?
Why does finding small effects in large studies indicate publication bias?
How can guns be countered by melee combat without raw-ability or exceptional explanations?
Ramanujan's radical and how we define an infinite nested radical
Reading source code and extracting json from a url
How does the income of your target audience matter for logo design?
Have the conservatives lost the working majority and if so, what does this mean?
Why would you use 2 alternate layout buttons instead of 1, when only one can be selected at once
Why is Bernie Sanders maximum accepted donation on actblue $5600?
Why didn't Lorentz conclude that no object can go faster than light?
TikZ-Tree with asymmetric siblings
Is Screenshot Time-tracking Common?
The Longest Chess Game
In a world with multiracial creatures, what word can be used instead of mankind?
Which was the first story to feature space elevators?
What is the optimal pipeline for updating table on FK value in Postgresql?
How do I insert a row which contains a foreign key?Inserting into related tablesPostgres multiple joins slow query, how to store default child recordWhat happens to the index of a primary key after a DROP CONSTRAINT?PostgreSQL - insert/update violates foreign key constraintsPossible to have nested inserts in Postgres 8.4?Simple PostgreSQL lookup table is inexplicably slowType of an id field that references another id fieldInserting in PostgreSQL Foreign Table Violates Primary Key Constraint10postgres: Upgraded RDS Postgres from 9.4 - 9.6, id fields went from SERIAL to INTPostgreSQL 9.5 query performance depends on JOINed column in SELECT clauseStandard behaviour in executing multiple alter statements in Postgres
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?
postgresql
add a comment |
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?
postgresql
1
You can insert into both tables in one statement in Postgres. See a similar question: dba.stackexchange.com/questions/46410/…
– ypercubeᵀᴹ
4 hours ago
How can I do it? Could you elaborate, please?
– Daniel Chepenko
4 hours ago
Sorry, this is a better example: dba.stackexchange.com/questions/89451/…
– ypercubeᵀᴹ
3 hours ago
ANd this: stackoverflow.com/questions/22775109/…
– ypercubeᵀᴹ
3 hours ago
add a comment |
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?
postgresql
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?
postgresql
postgresql
asked 4 hours ago
Daniel ChepenkoDaniel Chepenko
1083
1083
1
You can insert into both tables in one statement in Postgres. See a similar question: dba.stackexchange.com/questions/46410/…
– ypercubeᵀᴹ
4 hours ago
How can I do it? Could you elaborate, please?
– Daniel Chepenko
4 hours ago
Sorry, this is a better example: dba.stackexchange.com/questions/89451/…
– ypercubeᵀᴹ
3 hours ago
ANd this: stackoverflow.com/questions/22775109/…
– ypercubeᵀᴹ
3 hours ago
add a comment |
1
You can insert into both tables in one statement in Postgres. See a similar question: dba.stackexchange.com/questions/46410/…
– ypercubeᵀᴹ
4 hours ago
How can I do it? Could you elaborate, please?
– Daniel Chepenko
4 hours ago
Sorry, this is a better example: dba.stackexchange.com/questions/89451/…
– ypercubeᵀᴹ
3 hours ago
ANd this: stackoverflow.com/questions/22775109/…
– ypercubeᵀᴹ
3 hours ago
1
1
You can insert into both tables in one statement in Postgres. See a similar question: dba.stackexchange.com/questions/46410/…
– ypercubeᵀᴹ
4 hours ago
You can insert into both tables in one statement in Postgres. See a similar question: dba.stackexchange.com/questions/46410/…
– ypercubeᵀᴹ
4 hours ago
How can I do it? Could you elaborate, please?
– Daniel Chepenko
4 hours ago
How can I do it? Could you elaborate, please?
– Daniel Chepenko
4 hours ago
Sorry, this is a better example: dba.stackexchange.com/questions/89451/…
– ypercubeᵀᴹ
3 hours ago
Sorry, this is a better example: dba.stackexchange.com/questions/89451/…
– ypercubeᵀᴹ
3 hours ago
ANd this: stackoverflow.com/questions/22775109/…
– ypercubeᵀᴹ
3 hours ago
ANd this: stackoverflow.com/questions/22775109/…
– ypercubeᵀᴹ
3 hours ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230362%2fwhat-is-the-optimal-pipeline-for-updating-table-on-fk-value-in-postgresql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f230362%2fwhat-is-the-optimal-pipeline-for-updating-table-on-fk-value-in-postgresql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You can insert into both tables in one statement in Postgres. See a similar question: dba.stackexchange.com/questions/46410/…
– ypercubeᵀᴹ
4 hours ago
How can I do it? Could you elaborate, please?
– Daniel Chepenko
4 hours ago
Sorry, this is a better example: dba.stackexchange.com/questions/89451/…
– ypercubeᵀᴹ
3 hours ago
ANd this: stackoverflow.com/questions/22775109/…
– ypercubeᵀᴹ
3 hours ago