SQL 自动覆盖的书页索引
SQL Book page index with auto overwrite
我想实现类似书页的东西。
例如:
我有一本书有 100
页,每一页都有唯一的 priority/page 编号,(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 |
+-----+--------------------------------+------+
假设我插入了一个新页面,但在页面 50
和 51
之间。所以插入的第priority/page页数是51
.
因此,覆盖上面的页码,"OLD" 第 51-100 页将是 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 |
+-----+--------------------------------+------+
我正在使用 PostgreSQL、TypeORM、TypeScript。
--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
我想实现类似书页的东西。
例如:
我有一本书有 100
页,每一页都有唯一的 priority/page 编号,(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 |
+-----+--------------------------------+------+
假设我插入了一个新页面,但在页面 50
和 51
之间。所以插入的第priority/page页数是51
.
因此,覆盖上面的页码,"OLD" 第 51-100 页将是 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 |
+-----+--------------------------------+------+
我正在使用 PostgreSQL、TypeORM、TypeScript。
--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