Completely copying a postgres table with SQL

前端 未结 7 1252
春和景丽
春和景丽 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:45

    To copy a table completely, including both table structure and data, you use the following statement:

    CREATE TABLE new_table AS 
    TABLE existing_table;
    

    To copy a table structure without data, you add the WITH NO DATA clause to the CREATE TABLE statement as follows:

    CREATE TABLE new_table AS 
    TABLE existing_table 
    WITH NO DATA;
    

    To copy a table with partial data from an existing table, you use the following statement:

    CREATE TABLE new_table AS 
    SELECT
    *
    FROM
        existing_table
    WHERE
        condition;
    

提交回复
热议问题