Đây là chương trình của web_book bàn của tôi:PostgreSQL: làm thế nào để nhân đôi liên tiếp
Column | Type | Modifiers
----------------+------------------------+-------------------------------------------------------
id | integer | not null default nextval('web_book_id_seq'::regclass)
page_count | integer | not null
year_published | integer | not null
file | character varying(100) | not null
image | character varying(100) | not null
display_on_hp | boolean | not null
name | character varying(128) | not null
description | text | not null
name_cs | character varying(128) |
name_en | character varying(128) |
description_cs | text |
description_en | text |
Bảng này chứa một hàng với id=3
. Tôi muốn lặp lại hàng nhưng Nếu tôi cố gắng này:
INSERT INTO web_book SELECT * FROM web_book WHERE id=3;
tôi có được điều này:
ERROR: duplicate key value violates unique constraint "web_book_pkey"
DETAIL: Key (id)=(3) already exists
@clime Kể từ khi 'nextval' là mặc định cho môi trường 'cột id' nó không phải là cần thiết để khai báo nó. 'INSERT INTO web_book ( page_count, ...) SELECT page_count, ...' –
@ClodoaldoNeto: cảm ơn, điểm tốt. Tôi đã thêm vào đó. –
Tôi hiểu. Cảm ơn bạn! – clime