dm_get_pk() returns the names of the columns marked as primary key of a table of a dm object. If no primary key is set for the table, an empty character vector is returned.

dm_get_pk(dm, table)



A dm object.


A table in the dm.


A list with character vectors with the column name(s) of the primary keys of table.

Compound keys and multiple primary keys

Currently, keys consisting of more than one column are not supported. This feature is planned for dm 0.2.0. Therefore the function may return vectors of length greater than one in the future.

Similarly, each table currently can have only one primary key. This restriction may be lifted in the future. For this reason, and for symmetry with dm_get_fk(), this function returns a slit of character vectors.

See also

Other primary key functions: dm_add_pk(), dm_get_all_pks(), dm_has_pk(), enum_pk_candidates()


dm_nycflights13() %>% dm_get_pk(flights)
#> <list_of<character>[0]>
dm_nycflights13() %>% dm_get_pk(planes)
#> <list_of<character>[1]> #> [[1]] #> [1] "tailnum" #>