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

SELECT DISTINCT foo ON (bar) #1

Closed
gfredericks opened this issue Apr 9, 2013 · 4 comments
Closed

SELECT DISTINCT foo ON (bar) #1

gfredericks opened this issue Apr 9, 2013 · 4 comments

Comments

@gfredericks
Copy link
Contributor

I was trying to generate a SELECT DISTINCT ON (bar) foo recently and the only mechanism I could figure out was:

(-> (select :foo)
    (modifiers "DISTINCT ON (bar)")
    (sql/format))

;; => ["SELECT DISTINCT ON (BAR) foo "]

which feels like unintended usage, but at least works (at least because SQL isn't case-sensitive).

Is there a better way to do this, or a straightforward design as a new feature that I could add?

@jkk
Copy link
Collaborator

jkk commented Apr 9, 2013

Right now this isn't supported, but could be if a syntax for it can be worked out.

One thought: create a new :select-distinct clause (see honeysql.format/format-clause) that takes two sets of fields: one for the "on" fields, and one for the other fields. E.g.,

{:select-distinct [[:bar] [:foo]]}

or, with a helper defined:

(select-distinct [:bar] [:foo])

@gfredericks
Copy link
Contributor Author

Okay, that's helpful, thanks!

@jkk jkk closed this as completed in 7d4cc64 Aug 6, 2013
@jkk
Copy link
Collaborator

jkk commented Aug 6, 2013

you can do this now:

(-> (select (sql/call :distinct-on :bar) :foo) (sql/format))
=> ["SELECT DISTINCT ON (bar), foo"]

@jkk jkk reopened this Aug 6, 2013
@jkk jkk closed this as completed Aug 6, 2013
@emidln
Copy link
Contributor

emidln commented Jun 19, 2015

SELECT DISTINCT ON (bar), foo isn't legal in PostgreSQL at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants