SQL Book page index with auto overwrite
I want to achieve something like a Book pages.
e.g:
I have a book with 100
pages, each of page has unique priority/page number, (1-100).
+-----+--------------------------------+------+
| id | content | page |
+-----+--------------------------------+------+
| 1 | cover | 1 |
| 2 | prelude | 2 |
| ... | ... | ... |
| 50 | and so he do rig a jig jig... | 50 |
| 51 | and he come to the bus stop... | 51 |
| ... | ... | ... |
| 100 | back-cover | 100 |
+-----+--------------------------------+------+
Let's imagine I insert a new page, but between page 50
and 51
. So the inserted page priority/page number is 51
.
And so, overwrite the upper page number, the "OLD" page 51-100 would be 52-101.
+-----+--------------------------------+------+
| id | content | page |
+-----+--------------------------------+------+
| 1 | cover | 1 |
| 2 | prelude | 2 |
| ... | ... | ... |
| 50 | and so he do rig a jig jig... | 50 |
| 101 | this is a new page | 51 |
| 51 | and he come to the bus stop... | 52 |
| ... | ... | ... |
| 100 | back-cover | 101 |
+-----+--------------------------------+------+
I'm using PostgreSQL, TypeORM, TypeScript.
sql postgresql typescript typeorm
add a comment |
I want to achieve something like a Book pages.
e.g:
I have a book with 100
pages, each of page has unique priority/page number, (1-100).
+-----+--------------------------------+------+
| id | content | page |
+-----+--------------------------------+------+
| 1 | cover | 1 |
| 2 | prelude | 2 |
| ... | ... | ... |
| 50 | and so he do rig a jig jig... | 50 |
| 51 | and he come to the bus stop... | 51 |
| ... | ... | ... |
| 100 | back-cover | 100 |
+-----+--------------------------------+------+
Let's imagine I insert a new page, but between page 50
and 51
. So the inserted page priority/page number is 51
.
And so, overwrite the upper page number, the "OLD" page 51-100 would be 52-101.
+-----+--------------------------------+------+
| id | content | page |
+-----+--------------------------------+------+
| 1 | cover | 1 |
| 2 | prelude | 2 |
| ... | ... | ... |
| 50 | and so he do rig a jig jig... | 50 |
| 101 | this is a new page | 51 |
| 51 | and he come to the bus stop... | 52 |
| ... | ... | ... |
| 100 | back-cover | 101 |
+-----+--------------------------------+------+
I'm using PostgreSQL, TypeORM, TypeScript.
sql postgresql typescript typeorm
add a comment |
I want to achieve something like a Book pages.
e.g:
I have a book with 100
pages, each of page has unique priority/page number, (1-100).
+-----+--------------------------------+------+
| id | content | page |
+-----+--------------------------------+------+
| 1 | cover | 1 |
| 2 | prelude | 2 |
| ... | ... | ... |
| 50 | and so he do rig a jig jig... | 50 |
| 51 | and he come to the bus stop... | 51 |
| ... | ... | ... |
| 100 | back-cover | 100 |
+-----+--------------------------------+------+
Let's imagine I insert a new page, but between page 50
and 51
. So the inserted page priority/page number is 51
.
And so, overwrite the upper page number, the "OLD" page 51-100 would be 52-101.
+-----+--------------------------------+------+
| id | content | page |
+-----+--------------------------------+------+
| 1 | cover | 1 |
| 2 | prelude | 2 |
| ... | ... | ... |
| 50 | and so he do rig a jig jig... | 50 |
| 101 | this is a new page | 51 |
| 51 | and he come to the bus stop... | 52 |
| ... | ... | ... |
| 100 | back-cover | 101 |
+-----+--------------------------------+------+
I'm using PostgreSQL, TypeORM, TypeScript.
sql postgresql typescript typeorm
I want to achieve something like a Book pages.
e.g:
I have a book with 100
pages, each of page has unique priority/page number, (1-100).
+-----+--------------------------------+------+
| id | content | page |
+-----+--------------------------------+------+
| 1 | cover | 1 |
| 2 | prelude | 2 |
| ... | ... | ... |
| 50 | and so he do rig a jig jig... | 50 |
| 51 | and he come to the bus stop... | 51 |
| ... | ... | ... |
| 100 | back-cover | 100 |
+-----+--------------------------------+------+
Let's imagine I insert a new page, but between page 50
and 51
. So the inserted page priority/page number is 51
.
And so, overwrite the upper page number, the "OLD" page 51-100 would be 52-101.
+-----+--------------------------------+------+
| id | content | page |
+-----+--------------------------------+------+
| 1 | cover | 1 |
| 2 | prelude | 2 |
| ... | ... | ... |
| 50 | and so he do rig a jig jig... | 50 |
| 101 | this is a new page | 51 |
| 51 | and he come to the bus stop... | 52 |
| ... | ... | ... |
| 100 | back-cover | 101 |
+-----+--------------------------------+------+
I'm using PostgreSQL, TypeORM, TypeScript.
sql postgresql typescript typeorm
sql postgresql typescript typeorm
asked Nov 20 '18 at 15:14
Fransisco WijayaFransisco Wijaya
65110
65110
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
--Updates the table and sets each page value to itself + 1
--Under conditions: the page number is the same as the inserted record but the
--content is different (the original record with that page number)
--Or the page number is greater than the page number of the inserted record
UPDATE Table
SET [page] = [page] + 1
WHERE ([page] >= insertedPageNumber AND content <> insertedPageContent) OR [page] > insertedPageNumber
I'll try later tomorrow, busy right now.
– Fransisco Wijaya
Nov 20 '18 at 15:52
@FransiscoWijaya Ok. have a good day.
– Ryan Wilson
Nov 20 '18 at 15:52
I got a trouble again... UPDATE page SET "pageNumber" = "pageNumber" + 1 WHERE ("pageNumber" >= 1) OR "pageNumber" > 1 Key ("pageNumber")=(2) already exists.
– Fransisco Wijaya
Nov 21 '18 at 7:06
I know because I set the col to unique Is it possible to do it with UNIQUE?
– Fransisco Wijaya
Nov 21 '18 at 10:35
@FransiscoWijaya If the page you are inserting is page 1, it should increment the current page 1 to page 2, then page 2 would go to page 3 and so on. I'm having trouble understanding what your issue is.
– Ryan Wilson
Nov 21 '18 at 13:17
|
show 5 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53396050%2fsql-book-page-index-with-auto-overwrite%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
--Updates the table and sets each page value to itself + 1
--Under conditions: the page number is the same as the inserted record but the
--content is different (the original record with that page number)
--Or the page number is greater than the page number of the inserted record
UPDATE Table
SET [page] = [page] + 1
WHERE ([page] >= insertedPageNumber AND content <> insertedPageContent) OR [page] > insertedPageNumber
I'll try later tomorrow, busy right now.
– Fransisco Wijaya
Nov 20 '18 at 15:52
@FransiscoWijaya Ok. have a good day.
– Ryan Wilson
Nov 20 '18 at 15:52
I got a trouble again... UPDATE page SET "pageNumber" = "pageNumber" + 1 WHERE ("pageNumber" >= 1) OR "pageNumber" > 1 Key ("pageNumber")=(2) already exists.
– Fransisco Wijaya
Nov 21 '18 at 7:06
I know because I set the col to unique Is it possible to do it with UNIQUE?
– Fransisco Wijaya
Nov 21 '18 at 10:35
@FransiscoWijaya If the page you are inserting is page 1, it should increment the current page 1 to page 2, then page 2 would go to page 3 and so on. I'm having trouble understanding what your issue is.
– Ryan Wilson
Nov 21 '18 at 13:17
|
show 5 more comments
--Updates the table and sets each page value to itself + 1
--Under conditions: the page number is the same as the inserted record but the
--content is different (the original record with that page number)
--Or the page number is greater than the page number of the inserted record
UPDATE Table
SET [page] = [page] + 1
WHERE ([page] >= insertedPageNumber AND content <> insertedPageContent) OR [page] > insertedPageNumber
I'll try later tomorrow, busy right now.
– Fransisco Wijaya
Nov 20 '18 at 15:52
@FransiscoWijaya Ok. have a good day.
– Ryan Wilson
Nov 20 '18 at 15:52
I got a trouble again... UPDATE page SET "pageNumber" = "pageNumber" + 1 WHERE ("pageNumber" >= 1) OR "pageNumber" > 1 Key ("pageNumber")=(2) already exists.
– Fransisco Wijaya
Nov 21 '18 at 7:06
I know because I set the col to unique Is it possible to do it with UNIQUE?
– Fransisco Wijaya
Nov 21 '18 at 10:35
@FransiscoWijaya If the page you are inserting is page 1, it should increment the current page 1 to page 2, then page 2 would go to page 3 and so on. I'm having trouble understanding what your issue is.
– Ryan Wilson
Nov 21 '18 at 13:17
|
show 5 more comments
--Updates the table and sets each page value to itself + 1
--Under conditions: the page number is the same as the inserted record but the
--content is different (the original record with that page number)
--Or the page number is greater than the page number of the inserted record
UPDATE Table
SET [page] = [page] + 1
WHERE ([page] >= insertedPageNumber AND content <> insertedPageContent) OR [page] > insertedPageNumber
--Updates the table and sets each page value to itself + 1
--Under conditions: the page number is the same as the inserted record but the
--content is different (the original record with that page number)
--Or the page number is greater than the page number of the inserted record
UPDATE Table
SET [page] = [page] + 1
WHERE ([page] >= insertedPageNumber AND content <> insertedPageContent) OR [page] > insertedPageNumber
answered Nov 20 '18 at 15:17
Ryan WilsonRyan Wilson
3,9941619
3,9941619
I'll try later tomorrow, busy right now.
– Fransisco Wijaya
Nov 20 '18 at 15:52
@FransiscoWijaya Ok. have a good day.
– Ryan Wilson
Nov 20 '18 at 15:52
I got a trouble again... UPDATE page SET "pageNumber" = "pageNumber" + 1 WHERE ("pageNumber" >= 1) OR "pageNumber" > 1 Key ("pageNumber")=(2) already exists.
– Fransisco Wijaya
Nov 21 '18 at 7:06
I know because I set the col to unique Is it possible to do it with UNIQUE?
– Fransisco Wijaya
Nov 21 '18 at 10:35
@FransiscoWijaya If the page you are inserting is page 1, it should increment the current page 1 to page 2, then page 2 would go to page 3 and so on. I'm having trouble understanding what your issue is.
– Ryan Wilson
Nov 21 '18 at 13:17
|
show 5 more comments
I'll try later tomorrow, busy right now.
– Fransisco Wijaya
Nov 20 '18 at 15:52
@FransiscoWijaya Ok. have a good day.
– Ryan Wilson
Nov 20 '18 at 15:52
I got a trouble again... UPDATE page SET "pageNumber" = "pageNumber" + 1 WHERE ("pageNumber" >= 1) OR "pageNumber" > 1 Key ("pageNumber")=(2) already exists.
– Fransisco Wijaya
Nov 21 '18 at 7:06
I know because I set the col to unique Is it possible to do it with UNIQUE?
– Fransisco Wijaya
Nov 21 '18 at 10:35
@FransiscoWijaya If the page you are inserting is page 1, it should increment the current page 1 to page 2, then page 2 would go to page 3 and so on. I'm having trouble understanding what your issue is.
– Ryan Wilson
Nov 21 '18 at 13:17
I'll try later tomorrow, busy right now.
– Fransisco Wijaya
Nov 20 '18 at 15:52
I'll try later tomorrow, busy right now.
– Fransisco Wijaya
Nov 20 '18 at 15:52
@FransiscoWijaya Ok. have a good day.
– Ryan Wilson
Nov 20 '18 at 15:52
@FransiscoWijaya Ok. have a good day.
– Ryan Wilson
Nov 20 '18 at 15:52
I got a trouble again... UPDATE page SET "pageNumber" = "pageNumber" + 1 WHERE ("pageNumber" >= 1) OR "pageNumber" > 1 Key ("pageNumber")=(2) already exists.
– Fransisco Wijaya
Nov 21 '18 at 7:06
I got a trouble again... UPDATE page SET "pageNumber" = "pageNumber" + 1 WHERE ("pageNumber" >= 1) OR "pageNumber" > 1 Key ("pageNumber")=(2) already exists.
– Fransisco Wijaya
Nov 21 '18 at 7:06
I know because I set the col to unique Is it possible to do it with UNIQUE?
– Fransisco Wijaya
Nov 21 '18 at 10:35
I know because I set the col to unique Is it possible to do it with UNIQUE?
– Fransisco Wijaya
Nov 21 '18 at 10:35
@FransiscoWijaya If the page you are inserting is page 1, it should increment the current page 1 to page 2, then page 2 would go to page 3 and so on. I'm having trouble understanding what your issue is.
– Ryan Wilson
Nov 21 '18 at 13:17
@FransiscoWijaya If the page you are inserting is page 1, it should increment the current page 1 to page 2, then page 2 would go to page 3 and so on. I'm having trouble understanding what your issue is.
– Ryan Wilson
Nov 21 '18 at 13:17
|
show 5 more comments
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f53396050%2fsql-book-page-index-with-auto-overwrite%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