Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用此 postgres 命令复制表,但主键自动增量功能不会复制。有没有什么快速简单的方法可以做到这一点?谢谢!
CREATE TABLE table2 AS TABLE table;
这是我要做的:
BEGIN; LOCK TABLE oldtable; CREATE TABLE newtable (LIKE oldtable INCLUDING ALL); INSERT INTO newtable SELECT * FROM oldtable; SELECT setval('the_seq_name', (SELECT max(id) FROM oldtable)+1); COMMIT;
...虽然这是一件不寻常的事情,但我会对您要解决的问题感兴趣。