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
Note difference between UNION ALL and bind_rows evident below. As discussed at #1890, UNION CORRESPONDING is the equivalent to bind_rows (but not commonly implemented). May not be a good idea to have same verb with different behaviour:
library(dplyr)
pg<- src_postgres()
sql<-" WITH data AS (SELECT 1 AS a, 2 AS b) SELECT a, b FROM data UNION ALL SELECT b, a FROM data"
tbl(pg, sql(sql))
df<-
tbl(pg, sql("SELECT 1 AS a, 2 AS b")) %>%
collect()
df %>%
select(b, a) %>%
bind_rows(df %>% select(a, b))
SQL output:
> tbl(pg, sql(sql))
Source: postgres 9.6.0 [igow@localhost:5432/crsp]
From: <derived table> [?? x 2]
a b
(int) (int)
1 1 2
2 2 1
R output:
Source: local data frame [2 x 2]
b a
(int) (int)
1 2 1
2 2 1
union all
keeps rows even they are equal. Adding it would be pretty easy:sets.r
tbl-sql.r
The text was updated successfully, but these errors were encountered: