Create an index.

Share:

Description

Defines a new index on a PostgreSQL table.

Usage

1
2
dbIndex(conn, name, colname, idxname, unique = FALSE, method = c("btree",
  "hash", "rtree", "gist"), 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 associated.

idxname

A character string specifying the name of the index to be created. By default, this is the name of the table (without the schema) suffixed by _idx.

unique

Logical. Causes the system to check for duplicate values in the table when the index is created (if data already exist) and each time data is added. Attempts to insert or update data which would result in duplicate entries will generate an error.

method

The name of the method to be used for the index. Choices are "btree", "hash", "rtree", and "gist". The default method is "btree", although "gist" should be the index of choice for Post GIS spatial types (geometry, geography, raster).

display

Logical. Whether to display the query (defaults to TRUE).

exec

Logical. Whether to execute the query (defaults to TRUE).

Value

TRUE if the index was successfully created.

Author(s)

Mathieu Basille basille@ufl.edu

See Also

The PostgreSQL documentation: http://www.postgresql.org/docs/current/static/sql-createindex.html; the PostGIS documentation for GiST indexes: http://postgis.net/docs/using_postgis_dbmanagement.html#id541286

Examples

1
2
3
4
## examples use a dummy connection from DBI package
conn<-DBI::ANSI()
dbIndex(conn,name = c("fla", "bli"), colname = "geom", method = "gist",
    exec = FALSE)