key: Get or set the primary key for a table

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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

Usage

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## 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)

PivotalR documentation built on March 13, 2021, 1:06 a.m.