1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
# generates custom sql
Code
sql_table_analyze(con, in_schema("schema", "tbl"))
Output
<SQL> ANALYZE TABLE `schema`.`tbl`
---
Code
sql_query_explain(con, sql("SELECT * FROM table"))
Output
<SQL> EXPLAIN SELECT * FROM table
---
Code
left_join(lf, lf, by = "x", na_matches = "na")
Output
<SQL>
SELECT `df_LHS`.`x` AS `x`
FROM `df` AS `df_LHS`
LEFT JOIN `df` AS `df_RHS`
ON (`df_LHS`.`x` <=> `df_RHS`.`x`)
---
Code
full_join(lf, lf, by = "x")
Condition
Error in `sql_query_join()`:
! MySQL does not support full joins
---
Code
slice_sample(lf, n = 1)
Output
<SQL>
SELECT `x`
FROM (
SELECT *, ROW_NUMBER() OVER (ORDER BY RAND()) AS `q01`
FROM `df`
) `q01`
WHERE (`q01` <= 1)
---
Code
copy_inline(con, tibble(x = 1:2, y = letters[1:2])) %>% remote_query()
Output
<SQL> SELECT CAST(`x` AS INTEGER) AS `x`, CAST(`y` AS CHAR) AS `y`
FROM (
(
SELECT NULL AS `x`, NULL AS `y`
WHERE (0 = 1)
)
UNION ALL
(VALUES ROW(1, 'a'), ROW(2, 'b'))
) `values_table`
# `sql_query_update_from()` is correct
Code
sql_query_update_from(con = simulate_mysql(), x_name = ident("df_x"), y = df_y,
by = c("a", "b"), update_values = sql(c = "COALESCE(`df_x`.`c`, `...y`.`c`)",
d = "`...y`.`d`"), returning_cols = c("a", b2 = "b"))
Output
<SQL> UPDATE `df_x`
INNER JOIN (
SELECT `a`, `b`, `c` + 1.0 AS `c`, `d`
FROM `df_y`
) `...y`
ON `...y`.`a` = `df_x`.`a` AND `...y`.`b` = `df_x`.`b`
SET `df_x`.`c` = COALESCE(`df_x`.`c`, `...y`.`c`), `df_x`.`d` = `...y`.`d`
RETURNING `df_x`.`a`, `df_x`.`b` AS `b2`
# can explain
Code
db %>% mutate(y = x + 1) %>% explain()
Output
<SQL>
SELECT *, `x` + 1.0 AS `y`
FROM `test`
<PLAN>
id select_type table type possible_keys key key_len ref rows Extra
1 1 SIMPLE test ALL <NA> <NA> <NA> <NA> 3
|