> For the complete documentation index, see [llms.txt](https://docs.redivis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redivis.com/api/client-libraries/redivis-r/reference/redivis/redivisusdconnect_dbi.md).

# redivis$connect\_dbi

### **redivis$**<mark style="color:purple;">**connect\_dbi**</mark>**()** → [DBI::DBIConnection](https://dbi.r-dbi.org/reference/DBIConnection-class.html)

Returns a DBI connection that can be used by dbplyr and other interfaces that work with DBI. This connection will be globally scoped, and all table names must be appropriately qualified.

To create a connection scoped to particulary dataset or workflow, see:

* [Dataset$connect\_dbi()](/api/client-libraries/redivis-r/reference/dataset/datasetusdconnect_dbi.md)
* [Workflow$connect\_dbi()](/api/client-libraries/redivis-r/reference/workflow/workflowusdconnect_dbi.md)

{% hint style="info" %}
For advanced use cases, you can also access the Redivis DBI interface at `redivis::RedivisDBI`. `redivis$connect_dbi()` is the same as calling: `DBI::dbConnect(redivis::RedivisDBI())`
{% endhint %}

### **Returns:**

[**DBI::DBIConnection**](https://dbi.r-dbi.org/reference/DBIConnection-class.html)

### Examples

```r
con <- redivis$connect_dbi()

tbl(con, "demo.ghcn_daily_weather_data.stations") |> filter(latitude > 0) |> collect()

# Prints a tibble with the relevant weather stations
```

## Supported dplyr functions

DBI connections can be used with all of the standard dplyr verbs (`filter()`, `mutate()`, `summarise()`, joins, etc.). Within these verbs, the following R functions are translated to Redivis SQL:

| Category           | Functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Math and operators | `+`, `-`, `*`, `/`, `^`, `%%`, `%/%`, `%\|\|%`, `abs()`, `sqrt()`, `exp()`, `log()`, `log2()`, `log10()`, `round()`, `floor()`, `ceiling()`, `pmin()`, `pmax()`                                                                                                                                                                                                                                                                                                               |
| Type conversion    | `as.integer()`, `as.numeric()`, `as.double()`, `as.character()`, `as.logical()`, `as.Date()`, `as.POSIXct()`, `lubridate::as_date()`, `lubridate::as_datetime()`                                                                                                                                                                                                                                                                                                              |
| Conditionals       | `ifelse()`, `if_else()`, `case_when()`, `coalesce()`, `is.na()`, `between()`, `%in%`                                                                                                                                                                                                                                                                                                                                                                                          |
| Strings            | `nchar()`, `tolower()`, `toupper()`, `trimws()`, `paste()`, `paste0()`, `substr()`, `substring()`, `startsWith()`, `endsWith()`, `grepl()`, `sub()`, `gsub()`, and from stringr: `str_detect()`, `str_starts()`, `str_ends()`, `str_extract()`, `str_replace()`, `str_replace_all()`, `str_remove()`, `str_remove_all()`, `str_trim()`, `str_squish()`, `str_pad()`, `str_to_lower()`, `str_to_upper()`, `str_to_title()`, `str_c()`, `str_length()`, `str_sub()`             |
| Dates and times    | `Sys.Date()`, `Sys.time()`, `difftime()`, and from lubridate: `today()`, `now()`, `year()`, `isoyear()`, `quarter()`, `month()`, `week()`, `isoweek()`, `day()`, `mday()`, `yday()`, `wday()`, `hour()`, `minute()`, `second()`, `floor_date()`, and from clock: `get_year()`, `get_month()`, `get_day()`, `get_hour()`, `get_minute()`, `get_second()`, `add_days()`, `add_weeks()`, `add_months()`, `add_quarters()`, `add_years()`, `date_build()`, `date_count_between()` |
| Aggregates         | `n()`, `n_distinct()`, `sum()`, `mean()`, `min()`, `max()`, `sd()`, `var()`, `cor()`, `cov()`, `median()`, `quantile()`, `any()`, `all()`, and from stringr: `str_flatten()`                                                                                                                                                                                                                                                                                                  |
| Window functions   | `row_number()`, `min_rank()`, `rank()`, `dense_rank()`, `lead()`, `lag()`, `first()`, `last()`, `cumsum()`, and the aggregate functions above (other than `median()`, `quantile()`, `n_distinct()`, `str_flatten()`, `any()`, `all()`, `cor()`, and `cov()`)                                                                                                                                                                                                                  |

The following differences from R's behavior apply:

* `%/%` and `%%` round toward negative infinity, as in R, and always return a double.
* `median()` and `quantile()` are approximate. `quantile()` takes a single `probs` value.
* `str_replace()`, `str_remove()`, and `sub()` replace only the first match, and require a literal pattern and a replacement without backreferences. To use a column as the pattern, or to use backreferences, use `str_replace_all()` or `gsub()` to replace every match.
* `difftime()` only supports `units = "days"`, and `date_count_between()` only supports a `precision` of `"day"` or `"week"`.
* `month()` and `wday()` don't support `label = TRUE`, and `wday()` only supports `week_start = 7`. `floor_date()` doesn't support multiples of a unit (e.g., `"2 days"`).
* `second()` returns whole seconds.
* Redivis `dateTime` variables don't have a time zone, so `as.POSIXct()` and `Sys.time()` produce a `DATETIME`, and R `POSIXct` values used within a query are converted to UTC.

An error will be raised if a function is called with arguments that can't be translated.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.redivis.com/api/client-libraries/redivis-r/reference/redivis/redivisusdconnect_dbi.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
