Skip to content

Conversation

remiposo
Copy link

@remiposo remiposo commented Jul 4, 2025

PR Info

Changes

  • Changed arg_with to pub to specify FuncArgMod

@tyt2y3
Copy link
Member

tyt2y3 commented Jul 8, 2025

what do you need this method for? can you instead add a method similar to fn array_agg_distinct?

@remiposo
Copy link
Author

remiposo commented Jul 8, 2025

Thank you for your reply!

In my use case, I dynamically generate SQL with sea-query based on user requests.
While I understand that actual use cases are limited, I want to allow users to use DISTINCT with aggregate functions like SUM / AVG as long as it's valid SQL.
Is the reason you don't want to make args_with public to prevent invalid SQL from being generated for non-aggregate functions like ABS?

I could add xxx_distinct for all aggregate functions, but since I noticed that raw DISTINCT can be easily applied with cust_with_expr, I'm starting to feel that if there's less demand compared to count_distinct, it might not be worth adding specifically...

sea-query/src/expr.rs

Lines 1886 to 1891 in f778d36

/// let query = Query::select()
/// .expr(Expr::cust_with_expr(
/// "json_agg(DISTINCT $1)",
/// Expr::col(Char::Character),
/// ))
/// .to_owned();

@tyt2y3
Copy link
Member

tyt2y3 commented Aug 3, 2025

sorry for the delay, if count_distinct is what you need, let's just add that specifically!

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

Successfully merging this pull request may close these issues.

Enable using DISTINCT with any Function
2 participants