Skip to contents

dm_from_con() creates a dm from some or all tables in a src (a database or an environment) or which are accessible via a DBI-Connection. For Postgres and SQL Server databases, primary and foreign keys are imported from the database.


dm_from_con(con = NULL, table_names = NULL, learn_keys = NULL, ...)



A DBI::DBIConnection or a Pool object.


A character vector of the names of the tables to include.



Set to TRUE to query the definition of primary and foreign keys from the database. Currently works only for Postgres and SQL Server databases. The default attempts to query and issues an informative message.



Additional parameters for the schema learning query.

  • schema: supported for MSSQL (default: "dbo"), Postgres (default: "public"), and MariaDB/MySQL (default: current database). Learn the tables in a specific schema (or database for MariaDB/MySQL).

  • dbname: supported for MSSQL. Access different databases on the connected MSSQL-server; default: active database.

  • table_type: supported for Postgres (default: "BASE TABLE"). Specify the table type. Options are:

    1. "BASE TABLE" for a persistent table (normal table type)

    2. "VIEW" for a view

    3. "FOREIGN TABLE" for a foreign table

    4. "LOCAL TEMPORARY" for a temporary table


A dm object.


con <- dm_get_con(dm_financial())

#> Warning: `dm_from_src()` was deprecated in dm 0.3.0.
#>  Please use `dm_from_con()` instead.
#> Keys queried successfully, use `learn_keys = TRUE` to mute this message.
#> ── Table source ────────────────────────────────────────────────────────────────
#> src:  mysql  []
#> ── Metadata ────────────────────────────────────────────────────────────────────
#> Tables: `accounts`, `cards`, `clients`, `disps`, `districts`, … (9 total)
#> Columns: 57
#> Primary keys: 9
#> Foreign keys: 8

# Avoid DBI::dbDisconnect() here, because we don't own the connection