Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Detecting columns used in DISTINCT #2014

sampsonsl started this conversation in General
Discussion options

New to JSQLParser. I'd like to use it to identify columns used with specific SQL operations, like DISTINCT.
Suggestion on how this is best done, or pointers to examples appreciated. Thanks.

You must be logged in to vote

Replies: 1 comment 7 replies

Comment options

Greetings.

You would need to provide at least some sample SQLs to illustrate your question please.

You must be logged in to vote
7 replies
Comment options

Thanks. What is the specific method used to check the Distinct property?

Comment options

See JAVA API: https://manticore-projects.com/JSQLParser/javadoc_snapshot.html#plainselect
Use the method getDistinct() to access the Distinct object.

Comment options

Thank you for the guidance!

Comment options

Returning to this, using getDistinct() appears to work for cases where DISTINCT is used directly in the SELECT like my two earlier examples. However, "COUNT( DISTINCT )" produces getDistinct() == null.

For example, a query like this:

SELECT COUNT(DISTINCT s_i_id) FROM stock;

In this case, I think the parser is including s_i_d under COUNT as a function. I'm not clear how to find and associate it with DISTINCT. Suggestions appreciated. Thanks!

Comment options

It's a complete different type of distinct, belonging to a function call:

SQL Text
 └─Statements: statement.select.PlainSelect
 ├─selectItems: statement.select.SelectItem
 │ └─expression: expression.Function
 │ └─ExpressionList: s_i_id
 └─Table: stock

Java API: http://217.160.215.75:8080/jsqlformatter/JSQLParser/javadoc_snapshot.html#function
Which again has the method: isDistinct().

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

AltStyle によって変換されたページ (->オリジナル) /