has_idx.Rd
Check if the table holds an index on the specified columns and optionally check whether it is unique.
has_idx(conn, on_tbl, on_cols, keep_unique = FALSE, temp = FALSE)
An object of class SQLiteConnection
to a sqlite database.
A table in the database.
A character vector with the columns to check.
A logical. Additionally check if the index has the UNIQUE constraint. Default is FALSE.
Should sqlite_temp_master
be queried, instead of
sqlite_master
? Default is FALSE. This can be useful when looking for
temporary tables and indexes on them.
A logical.
The function only checks exact matching of on_cols
, that is, the
order of columns in on_cols
needs to correspond to the order of columns in
the CREATE INDEX statement: If on_cols = c("col1", "col2")
, but the
database has "CREATE UNIQUE INDEX idx1 ON mytable(col2, col1)"
,
the function will return FALSE.
conn <- connect_to_db(db_example("AcademicGraph.sqlite"))
#> The database connection is:
#> src: sqlite 3.38.5 [/tmp/RtmptPxKJr/temp_libpath72cc939d74f39/magutils/extdata/AcademicGraph.sqlite]
#> tbls: AuthorAffiliation, FieldsOfStudy, FirstNamesGender, author_coauthor,
#> author_output, current_links, current_links_advisors, pq_advisors,
#> pq_authors, pq_fields_mag, pq_unis
has_idx(conn, "author_output", "AuthorId", keep_unique = TRUE)
#> [1] FALSE