Learn R Programming

rpostgis (version 1.0.0)

dbAddKey: Add key.

Description

Add a primary or foreign key to a table column.

Usage

dbAddKey(conn, name, colname, type = c("primary", "foreign"), reference, colref, display = TRUE, exec = TRUE)

Arguments

conn
A connection object.
name
A character string specifying a PostgreSQL table name.
colname
A character string specifying the name of the column to which the key will be assign.
type
The type of the key, either primary or foreign
reference
A character string specifying a foreign table name to which the foreign key will be associated.
colref
A character string specifying the name of the primary key in the foreign table to which the foreign key will be associated.
display
Logical. Whether to display the query (defaults to TRUE).
exec
Logical. Whether to execute the query (defaults to TRUE).

Value

TRUE if the key was successfully added.

See Also

The PostgreSQL documentation: http://www.postgresql.org/docs/current/static/sql-altertable.html

Examples

Run this code
## examples use a dummy connection from DBI package
conn<-DBI::ANSI()
dbAddKey(conn, name = c("fla", "bli"), colname = "id", type = "foreign",
    reference = c("flu", "bla"), colref = "id", exec = FALSE)

Run the code above in your browser using DataLab