View source: R/all_db_wrapper_fns.R
dbIndex | R Documentation |
Defines a new index on a PostgreSQL table.
dbIndex(
conn,
name,
colname,
idxname,
unique = FALSE,
method = c("btree", "hash", "rtree", "gist"),
display = TRUE,
exec = TRUE
)
conn |
A connection object. |
name |
A character string specifying a PostgreSQL table name. |
colname |
A character string, or a character vector specifying the name of the column to which the key will be associated; alternatively, a character vector specifying the name of the columns to build the index. |
idxname |
A character string specifying the name of the index
to be created. By default, this uses the name of the table
(without the schema) and the name of the columns as follows:
|
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 |
display |
Logical. Whether to display the query (defaults to
|
exec |
Logical. Whether to execute the query (defaults to
|
If exec = TRUE
, returns TRUE
if the index was
successfully created.
Mathieu Basille mathieu@basille.org
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 use a dummy connection from DBI package
conn <- DBI::ANSI()
## GIST index
dbIndex(conn, name = c("sch", "tbl"), colname = "geom", method = "gist",
exec = FALSE)
## Regular BTREE index on multiple columns
dbIndex(conn, name = c("sch", "tbl"), colname = c("col1", "col2",
"col3"), exec = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.