Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering on mutate() columns in Greenplum #484

Closed
patrick-nicholson opened this issue Jul 7, 2014 · 3 comments
Closed

Filtering on mutate() columns in Greenplum #484

patrick-nicholson opened this issue Jul 7, 2014 · 3 comments
Assignees
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@patrick-nicholson
Copy link

Using filter on a column created by mutate (in this case rnk) fails with the error

> dp %>% mutate(rnk = min_rank(desc(salary))) %>% filter(rnk == 1)
Error in postgresqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (could not Retrieve the result : ERROR:  column "rnk" does not exist
LINE 3: WHERE "rnk" = 1.0) AS master
              ^
)

However, selecting the column rnk works:

> dp %>% mutate(rnk = min_rank(desc(salary))) %>% select(rnk)
   rnk
1    1
2    2
3    3
...

Due to the setup of R and Greenplum I have to use, I can't provide a replicable example. I'm not sure if this is a psql issue or specific to Greenplum. I don't get errors using local dataframes or sqlite.

@hadley
Copy link
Member

hadley commented Jul 8, 2014

Could you please me the generated SQL? (Call the object x and then use x$sql

@patrick-nicholson
Copy link
Author

SELECT "first_name", "last_name", "emp_id", "hire_date", "salary", "dept",
       "exempt", "interests", rank() OVER (ORDER BY "salary" DESC) AS "rnk"
FROM "emp"
WHERE "rnk" = 1.0

@hadley
Copy link
Member

hadley commented Jul 8, 2014

Oh hmm, I didn't think about using window functions when the data isn't grouped. It needs an intermediate subquery.

@hadley hadley added this to the 0.3 milestone Aug 1, 2014
@hadley hadley self-assigned this Aug 1, 2014
@hadley hadley closed this as completed in 3ad8f46 Aug 28, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants