Completely copying a postgres table with SQL

前端 未结 7 1233
春和景丽
春和景丽 2021-01-30 06:13

DISCLAIMER: This question is similar to the stack overflow question here, but none of those answers work for my problem, as I will explain later.

I\'m t

7条回答
  •  隐瞒了意图╮
    2021-01-30 06:43

    The closest "miracle command" is something like

    pg_dump -t tablename | sed -r 's/\btablename\b/tablename_copy/' | psql -f -
    

    In particular, this takes care of creating the indexes after loading the table data.

    But that doesn't reset the sequences; you will have to script that yourself.

提交回复
热议问题