Skip to content

LIKE operator produces different result than in T-SQL, leaks implementation detail #31

@dallmair

Description

@dallmair

Run the following query on Microsoft SQL Server and in NQuery:

SELECT CASE WHEN '2.10.1' LIKE '2.1.%' THEN 1 ELSE 0 END

SQL produces 0, because '2.1.' doesn't match '2.10' as '.' differs from '0'. Unfortunately NQuery produces 1, because it compiles the match string to a regular expression and doesn't escape the dot character. So NQuery leaks an implementation detail to the user.

There's a workaround until the bug is fixed: Manually escape the match string with REGEX_ESCAPE. With this workaround the query looks as follows:

SELECT CASE WHEN '2.10.1' LIKE REGEX_ESCAPE('2.1.%') THEN 1 ELSE 0 END

Not great, but at least it works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions