From 5fe65c904291e57f7011d57223b3390e8f8e74c7 Mon Sep 17 00:00:00 2001 From: Michael Thomson Date: Thu, 11 Apr 2024 04:38:16 +0000 Subject: [PATCH 1/3] add comments to characterize the intended non-SQL roots for months() and days() --- R/backend-postgres.R | 3 +++ R/backend-snowflake.R | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/R/backend-postgres.R b/R/backend-postgres.R index 5f9f0ba6f..b607443fe 100644 --- a/R/backend-postgres.R +++ b/R/backend-postgres.R @@ -215,13 +215,16 @@ sql_translation.PqConnection <- function(con) { hours = function(x) { postgres_period(x, "hours") }, + days = function(x) { + # lubridate::days() (base::days() does not exist) postgres_period(x, "days") }, weeks = function(x) { postgres_period(x, "weeks") }, months = function(x) { + # base::months() (or applicable methods from lubridate, e.g., months.numeric) postgres_period(x, "months") }, years = function(x) { diff --git a/R/backend-snowflake.R b/R/backend-snowflake.R index afb696f2d..d7461dcde 100644 --- a/R/backend-snowflake.R +++ b/R/backend-snowflake.R @@ -100,9 +100,7 @@ sql_translation.Snowflake <- function(con) { str_squish = function(string) { sql_expr(regexp_replace(trim(!!string), "\\\\s+", " ")) }, - - - # lubridate functions + # date functions (e.g., functions covered by lubridate or ?base::weekdays) # https://docs.snowflake.com/en/sql-reference/functions-date-time.html day = function(x) { sql_expr(EXTRACT(DAY %FROM% !!x)) @@ -188,12 +186,14 @@ sql_translation.Snowflake <- function(con) { glue_sql2(sql_current_con(), "INTERVAL '{.val x} hour'") }, days = function(x) { + # lubridate::days() (base::days() does not exist) glue_sql2(sql_current_con(), "INTERVAL '{.val x} day'") }, weeks = function(x) { glue_sql2(sql_current_con(), "INTERVAL '{.val x} week'") }, months = function(x) { + # base::months() (or applicable methods from lubridate, e.g., months.numeric) glue_sql2(sql_current_con(), "INTERVAL '{.val x} month'") }, years = function(x) { From f7213672692be228b33f88385d5afc1eb363e1d5 Mon Sep 17 00:00:00 2001 From: Michael Thomson Date: Thu, 11 Apr 2024 04:45:11 +0000 Subject: [PATCH 2/3] simplify --- R/backend-snowflake.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/backend-snowflake.R b/R/backend-snowflake.R index d7461dcde..d27f5ad7e 100644 --- a/R/backend-snowflake.R +++ b/R/backend-snowflake.R @@ -100,7 +100,7 @@ sql_translation.Snowflake <- function(con) { str_squish = function(string) { sql_expr(regexp_replace(trim(!!string), "\\\\s+", " ")) }, - # date functions (e.g., functions covered by lubridate or ?base::weekdays) + # date functions (e.g., from lubridate or ?base::weekdays) # https://docs.snowflake.com/en/sql-reference/functions-date-time.html day = function(x) { sql_expr(EXTRACT(DAY %FROM% !!x)) From 2cc458f12536fb8c28319d26a40bb2713f8a29eb Mon Sep 17 00:00:00 2001 From: Michael Thomson Date: Thu, 2 May 2024 20:03:14 +0000 Subject: [PATCH 3/3] linebreak --- R/backend-postgres.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/backend-postgres.R b/R/backend-postgres.R index b607443fe..288849bde 100644 --- a/R/backend-postgres.R +++ b/R/backend-postgres.R @@ -215,7 +215,6 @@ sql_translation.PqConnection <- function(con) { hours = function(x) { postgres_period(x, "hours") }, - days = function(x) { # lubridate::days() (base::days() does not exist) postgres_period(x, "days")