Skip to content

Conversation

@jechol
Copy link
Contributor

@jechol jechol commented Dec 30, 2025

Depends on ash-project/ash#2497

Summary

Add SQL translation for is_distinct_from and is_not_distinct_from functions to PostgreSQL's IS DISTINCT FROM and IS NOT DISTINCT FROM operators.

Example

# Ash query
Order
|> Ash.Query.filter(is_distinct_from(shipping_phone, primary_phone))

# Generated SQL
WHERE shipping_phone IS DISTINCT FROM primary_phone

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Add support for generating SQL IS DISTINCT FROM and IS NOT DISTINCT FROM expressions.

- Update AshSql.Expr to handle :is_distinct_from and :is_not_distinct_from operators
- Generate proper SQL: "expr1 IS DISTINCT FROM expr2" and "expr1 IS NOT DISTINCT FROM expr2"

This enables NULL-safe comparisons in SQL queries generated by AshSql.

Related to ash-project/ash#2493
…ions

Add SQL translation for Ash.Query.Function.IsDistinctFrom and IsNotDistinctFrom.

Changes:
- Import IsDistinctFrom and IsNotDistinctFrom functions
- Add unified handler for both functions using pattern matching
- Generate SQL IS DISTINCT FROM and IS NOT DISTINCT FROM operators
- Remove old operator-based handling code

Implementation:
- Both functions handled in single default_dynamic_expr clause
- Uses guard clause: when mod in [IsDistinctFrom, IsNotDistinctFrom]
- SQL fragment selection via case statement
- Enables NULL-safe comparisons in PostgreSQL queries
@jechol jechol changed the title feat: add SQL generation for is_distinct_from operators feat: add support for is_distinct_from and is_not_distinct_from functions Dec 31, 2025
Copy link
Contributor

@zachdaniel zachdaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small changes requested but otherwise looks great!

jechol and others added 3 commits January 1, 2026 20:31
Co-authored-by: Zach Daniel <zachary.s.daniel@gmail.com>
Co-authored-by: Zach Daniel <zachary.s.daniel@gmail.com>
@jechol
Copy link
Contributor Author

jechol commented Jan 1, 2026

Done! Ready for another look. 👍

@zachdaniel zachdaniel merged commit fe5d6bf into ash-project:main Jan 1, 2026
22 of 23 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

@jechol jechol deleted the feat/is-distinct-from branch January 1, 2026 23:41
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.

2 participants