key: Get or set the primary key for a table

keyR Documentation

Get or set the primary key for a table

Description

This function gets or sets the primary key for a db.obj table.

Usage

key(x)

key(x) <- value

Arguments

x

is a db.obj object.

value

must be a string.

Details

key() will return the primary key of a table. If the primary key is not set, key() will return the character 0. If key() is being used to set the primary key, then value must be a string, and it must match one of the column names in the table.

If this function is used to change the primary key to a new column name, this function does NOT check if all the values in that column are unique.

Value

The return value is the primary key of the table.

Author(s)

Author: Predictive Analytics Team at Pivotal Inc.

Maintainer: Frank McQuillan, Pivotal Inc. fmcquillan@pivotal.io

See Also

lk or lookat Displays the contents of a db.obj object.

Examples

## Not run: 


## set up the database connection
## Assume that .port is port number and .dbname is the database name
cid <- db.connect(port = .port, dbname = .dbname, verbose = FALSE)

## create a table from the example data.frame "abalone"
tmp <- as.db.data.frame(abalone, conn.id = cid, verbose = FALSE)
x <- db.data.frame(content(tmp), key = 'id', conn.id = cid, verbose = FALSE)

## getting the primary key
key(x) # Display the primary key for x

## Changing the primary key
key(x) <- 'length'

db.disconnect(cid, verbose = FALSE)

## End(Not run)

greenplum-db/GreenplumR documentation built on Sept. 2, 2023, 8:09 a.m.