Skip to content
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

* `across(everything())` doesn't select grouping columns created via `.by` in
`summarise()` (@mgirlich, #1493).
* Use `COUNT_BIG` instead of `COUNT` for SQL server so that `tally()` and
`count()` work regardless of size of the data (@edward-burn, #1498).

* New translations of clock function `date_count_between()` for SQL server, Redshift, Snowflake, Postgres, and Spark (@edward-burn, #1495).

Expand Down
4 changes: 4 additions & 0 deletions R/backend-mssql.R
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ simulate_mssql <- function(version = "15.0") {
sql_variant(
mssql_scalar,
sql_translator(.parent = base_odbc_agg,
# Use COUNT_BIG to ensure result is always returned regardless of table size
# COUNT errors if more than 2,147,483,647 rows are present due to an integer overflow
# https://learn.microsoft.com/en-us/sql/t-sql/functions/count-transact-sql?view=sql-server-ver17
n = function() sql("COUNT_BIG(*)"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please include a comment with a link to the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, now added!

sd = sql_aggregate("STDEV", "sd"),
var = sql_aggregate("VAR", "var"),
str_flatten = function(x, collapse = "") sql_expr(string_agg(!!x, !!collapse)),
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/_snaps/backend-mssql.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,38 @@
FROM `df`
ORDER BY `y`

# count_big
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did these snapshots come from? I don't see a corresponding test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not sure how that happened. Have now added test and updated snapshots


Code
dplyr::count(mf)
Output
<SQL>
SELECT COUNT_BIG(*) AS `n`
FROM `df`

---

Code
dplyr::tally(mf)
Output
<SQL>
SELECT COUNT_BIG(*) AS `n`
FROM `df`

# can copy_to() and compute() with temporary tables (#438)

Code
db <- copy_to(con, df, name = unique_table_name(), temporary = TRUE)
Message
Created a temporary table named #dbplyr_{tmp}

---

Code
db2 <- db %>% mutate(y = x + 1) %>% compute()
Message
Created a temporary table named #dbplyr_{tmp}

# add prefix to temporary table

Code
Expand Down
Loading