copy

This article covers both the copy and move statements. They both work in the same way apart from the fact that move deletes the source row after copying it.

Overview

The copy statement is used to copy rows from one DSET to another

Syntax

copy rows todset.id

move rows todset.id

Details

Both copy and move must be used within the body of a where statement. Only rows that match the expression will be copied (or moved).

  • The DSET from which rows will be copied or moved is automatically determined from the expression used by the where statement.

  • The DSET to which rows will be copied or moved is determined by the dset.id parameter

The source and destination DSETs must be different (it is not possible to copy or move a row within the same DSET).

The destination DSET may or may not exist. If it does not exist then it will be created. If it does exist then the following logic is applied:

  • If the destination DSET has more columns than the source DSET then the new rows in the destination DSET will have blank values in the rightmost columns

  • If the destination DSET has fewer columns than the source DSET then the destination DSET will be extended with enough new columns to accommodate the new rows. In this case, existing rows in the destination DSET will have blank values in the rightmost columns

If the destination DSET is extended to accommodate the source rows then the new (rightmost) columns will have the same names as the equivalent columns in the source DSET. In the event that this would cause a naming conflict with existing columns in the destination DSET, one or more new columns in the destination DSET will have a suffix added to their name to ensure uniqueness. This suffix takes the form _N where N is a number starting at 2.

To illustrate this, if the source DSET has columns called subscription,name,address,hostname and the destination DSET has a single column called name then the resulting extended destination DSET would have columns called name,subscription,name_2,address,hostname.

Example

# Move all rows in usage.data where hostname is "test server"
# to a new DSET called test.servers

where ([usage.data.hostname] == "test server") {
    move rows to test.servers
}

Last updated