Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 2, 2025

This PR fixes the issue where SELECT null IN () and SELECT null NOT IN () were returning NULL instead of the expected false and true values respectively.

Changes Made

  • Fixed Expression Compiler (src/50expression.js):

    • Added a skipNullCheck flag to the expression compilation logic
    • When the right side of IN/NOT IN is an empty array, the flag bypasses null-checking logic since the result is deterministic
    • For empty arrays: IN () always returns false (nothing is in an empty set), NOT IN () always returns true (everything is not in an empty set)
    • This follows SQL standard behavior where operations on empty sets have deterministic results regardless of null operands
  • Added Test Case (test/test1529.js):

    • Tests that null IN () returns false
    • Tests that null NOT IN () returns true
    • Verifies non-null values still work correctly with empty sets

Testing

  • ✅ All new tests pass
  • ✅ Existing IN/NOT IN operator tests still pass (test248.js, test024.js, test053.js)
  • ✅ Build process completes successfully
  • ✅ No security vulnerabilities introduced (CodeQL analysis clean)

The fix is minimal and surgical, only affecting the specific case of empty arrays in IN/NOT IN operators with null operands, while preserving all existing behavior for non-empty sets and non-null operands.

Original prompt

This section details on the original issue you should resolve

<issue_title>SELECT null [not] IN ()</issue_title>
<issue_description>Derived from https://github.com/AlaSQL/alasql-sqllogictest/blob/a10ff82e75edafae2ce96c9d02ab47cfc85d4507/results/output.md#1620-testevidencein1test


SELECT null IN ()

Expected: false but got NULL


SELECT null NOT IN ()

Expected: true but got NULL

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 2, 2025
@mathiasrw
Copy link
Member

@copilot Continue

Copy link
Contributor Author

Copilot AI commented Dec 4, 2025

@copilot Continue

I've implemented the fix for the null IN/NOT IN empty set issue. The changes are in commit 4135361.

The fix ensures that:

  • SELECT null IN () returns false (nothing is in an empty set)
  • SELECT null NOT IN () returns true (everything is not in an empty set)

This is achieved by adding a skipNullCheck flag that bypasses the null-checking logic when the IN/NOT IN operator has an empty array on the right side, since the result is deterministic regardless of whether the left operand is null.

Copilot AI changed the title [WIP] Fix behavior of null in IN and NOT IN operators Fix behavior of null in IN and NOT IN operators with empty sets Dec 4, 2025
Copilot finished work on behalf of mathiasrw December 4, 2025 03:18
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.

SELECT null [not] IN ()

2 participants