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

Add "DISTINCT ON" clause for SELECT #48

Closed
wants to merge 1 commit into from

Conversation

ikozinov
Copy link

I couldn't use the extensibility features for sqlbuilder, so I added "distinct on" clause support for PostgreSQL right in sqlbuilder

@huandu
Copy link
Owner

huandu commented Aug 30, 2020

Thanks for your contribution.

DISTINCT ON clause is a PostgreSQL-specific syntax. I don't think it's suitable to add it to SelectBuilder as a general API which should work for both MySQL and PostgreSQL.

However, it's reasonable to enable package users to build this clause with SelectBuilder. I'm think of a design with which we cna add any SQL clause to a builder freely.

A rough design looks like following.

// New API SQL() enables us to add any SQL after any clause generated by a builder.
// In this case, as SelectBuilder always starts with SELECT,
// the clause added by SQL() is inserted after SELECT.
sb.SQL("DISTINCT ON (col1, col2)").Select("col3", "col4")

Any feedback? You suggestion is highly appereciated.

@huandu huandu closed this Feb 3, 2021
huandu added a commit that referenced this pull request Feb 3, 2021
All builders add a new method called SQL to enable us to add any
arbitrary SQL when building. It's quite useful when we are using some
kinds of extension syntax or add special comments in SQL.
huandu added a commit that referenced this pull request Feb 3, 2021
Fix #48 #49 #53: Add new method SQL in all builders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants