Vertica Analytics Platform Version 9.2.x Documentation
Copies one table to another. This lightweight, in-memory copy increases performance by initially sharing the same storage between two tables. The copied table includes copies of any explicitly created projections from the source table. Once copied, the source and copy tables are independent of each other. Users can perform operations on one table without impacting the other. These operations can increase the overall storage required for both tables.
Creating multiple, concurrent copies of the same table may cause some of the copies to fail. To ensure success, copy tables sequentially.
Although they share storage space, Vertica considers the tables as discrete objects for license capacity purposes. For example, copying a one TB table would only consume one TB of space. Your Vertica license, however, considers them as separate objects consuming two TB of space.
COPY_TABLE ( '[[database.]schema.]source-table', '[[database.]schema.]target-table' )
Specifies a schema, by default
If you specify a database, it must be the current database.
|source‑table||The source table to copy. Vertica copies all data from this table to the target table.|
The target table of the source table. If the target table already exists, Vertica appends the source to the existing table.
If the table does not exist, Vertica creates a table from the source table's definition, by calling
- User must have INSERT, UPDATE, DELETE and SELECT privileges on the source table.
- User must have CREATE privileges on the target table and target table schema if
COPY_TABLEis creating a new table.
- User must have INSERT privileges on the target table if
COPY_TABLEis adding to an existing table.
Table Attribute Requirements
The following attributes of both tables must be identical:
- Column definitions, including NULL/NOT NULL constraints
- Partitioning expression
- Number of projections
- Projection sort order
- Primary and unique key constraints. However, the key constraints do not have to be identically enabled.
If the target table has primary or unique key constraints enabled and moving the partitions will insert duplicate key values into the target table, Vertica rolls back the operation. Enforcing constraints requires disk reads and can slow the copy process.
- Number and definitions of text indices.
The following restrictions apply to the source and target tables:
- If the source and target partitions are in different storage tiers, Vertica returns a warning but the operation proceeds. The partitions remain in their existing storage tier.
- If the source table contains a sequence, Vertica converts the sequence to an integer before copying it to the target table. If the target table contains auto-increment, identity, or named sequence columns, Vertica cancels the copy and displays an error message.
- The following tables cannot be used as sources or targets:
- Temporary tables
- Virtual tables
- System tables
- External tables
If you call
COPY_TABLE and the target table does not exist, the function creates the table automatically. In the following example, the target table
public.newtable does not exist.
COPY_TABLE creates the table and replicates the source table. Vertica also copies all the constraints associated with the source table except foreign key constraints.
=> SELECT COPY_TABLE ( 'public.product_dimension', 'public.newtable'); -[ RECORD 1 ]-------------------------------------------------- copy_table | Created table public.newtable. Copied table public.product_dimension to public.newtable
Was this topic helpful?