Skip to content

Median translated incorrectly for SQLite #357

Description

@GrayAlex49

Using dplyr to work with data from a database, the median function does not seem to be translating correctly. Mean works as expected but median does not. I'm using a mysql database but can recreate the problem in sqlite.

mf <- memdb_frame(group = c("a", "a", "b", "b", "c"), 
                  year = c(2010, 2010, 2012, 2013, 2010), 
                  var1 = 5:1,
                  var2 = 100:104)

mf %>% 
  group_by(group, year) %>% 
  summarise_at(vars(one_of("var1", "var2")), median)


mf %>% 
  group_by(group, year) %>% 
  summarise_at(vars(one_of("var1", "var2")), mean)

This error is rather unhelpful, on my actual data I was getting something like

'AS temp, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY var1) AS var1, at line 1 [1064]

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementfunc trans 🌍Translation of individual functions to SQL

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions