Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arithmetic overflow error converting expression to data type int. #516

Open
JeffreySumner opened this issue Feb 14, 2024 · 0 comments
Open

Comments

@JeffreySumner
Copy link

Prework

Description

When using pointblank::scan_data() on a "tbl_Microsoft SQL Server" I receive the following error:
Arithmetic overflow error converting expression to data type int.

Reproducible example

I don't have a reproducible example readily available as I'm using this in a work setting but can attempt to create one later one if needed.

Expected result

The SQL query created is as follows:

SELECT
AVG("X") AS "mean",
MIN("X") AS "min",
MAX("X") AS "max"
FROM (
SELECT "X"
FROM "table_name"
) "q01"'

This is a common issue I see in Microsoft SQL Server and the simple fix is:

SELECT
AVG(CAST("X" as float)) AS "mean",
MIN(CAST("X" as float)) AS "min",
MAX(CAST("X" as float)) AS "max"
FROM (
SELECT "X"
FROM "table_name"
) "q01"'

The way I did this via dbplyr was

table_name %>% select(X) %>% summarize( mean = mean(X%>% as.numeric()) , min = min(X%>% as.numeric()) , max = max(X%>% as.numeric()) ) %>% show_query() %>% collect()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants