You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some SQL engines such as BigQuery provide a way to define temporary user function using the CREATE TEMP FUNCTION syntax. It's similar as create temporary table with the WITH table_name AS syntax but for function
Here I'm replicating WIDTH_BUCKET function from PostgreSQL which isn't available natively in BigQuery:
{sql}
CREATE TEMP FUNCTION WIDTH_BUCKET(
value NUMERIC,
min_value NUMERIC,
max_value NUMERIC,
num_buckets NUMERIC
) AS (
RANGE_BUCKET(
value,
GENERATE_ARRAY(
min_value,
max_value,
(max_value - min_value) / num_buckets
)
)
);
SELECT
x,
WIDTH_BUCKET(x, 0, MAX(x) OVER(), 4) as rank_equ_range,
NTILE(4) OVER(ORDER BY x) AS rank_equ_member
FROM
UNNEST([1, 1, 2, 5, 6, 7, 8, 9, 48, 100]) AS x
However, it's being executed with dbExecute because it match the CREATE keyword here
The possible fix is to exclude the CREATE FUNCTION or CREATE TEMP FUNCTION keyword from the matcher, something like this (I'm bad at regex) CREATE[\s]+(TEMP[\s]+FUNCTION|FUNCTION) but using exclude rule
Or perhaps making a new cell option to force treat it as non-update query, which I'm not sure how to do it
The text was updated successfully, but these errors were encountered:
Some SQL engines such as BigQuery provide a way to define temporary user function using the
CREATE TEMP FUNCTION
syntax. It's similar as create temporary table with theWITH table_name AS
syntax but for functionHere I'm replicating
WIDTH_BUCKET
function from PostgreSQL which isn't available natively in BigQuery:However, it's being executed with
dbExecute
because it match theCREATE
keyword hereknitr/R/engine.R
Line 561 in fb1f423
knitr/R/engine.R
Line 618 in fb1f423
Hence returning no result if I use SQL code chunk directly
Currently, I'm using this workaround to execute it directly in R
Which has an actual output instead of empty like
dbExecute
The possible fix is to exclude the CREATE FUNCTION or CREATE TEMP FUNCTION keyword from the matcher, something like this (I'm bad at regex)
CREATE[\s]+(TEMP[\s]+FUNCTION|FUNCTION)
but using exclude ruleOr perhaps making a new cell option to force treat it as non-update query, which I'm not sure how to do it
The text was updated successfully, but these errors were encountered: