-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 7 replies
-
Greetings.
You would need to provide at least some sample SQLs to illustrate your question please.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks. What is the specific method used to check the Distinct property?
Beta Was this translation helpful? Give feedback.
All reactions
-
See JAVA API: https://manticore-projects.com/JSQLParser/javadoc_snapshot.html#plainselect
Use the method getDistinct()
to access the Distinct
object.
Beta Was this translation helpful? Give feedback.
All reactions
-
😄 1
-
Thank you for the guidance!
Beta Was this translation helpful? Give feedback.
All reactions
-
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!
Beta Was this translation helpful? Give feedback.
All reactions
-
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()
.
Beta Was this translation helpful? Give feedback.