Skip to content

[Bug]: PATINDEX fails with '(' or ')' in search pattern #4296

@gusmerle

Description

@gusmerle

What happened?

If the search pattern in PATINDEX contains an opening or closing parentheses sign, PATINDEX fails on babelfish (but it works on MSSQL)

set nocount on
select @@version
go
select patindex('%(%','the phone Nr is 1-(800)-CARS') [left_par]
go
select patindex('%)%','the phone Nr is 1-(800)-CARS') [right_par]
go

version
-------------------------------------------------------------------------
Babelfish for PostgreSQL with SQL Server Compatibility - 12.0.2000.8
Jul  6 2025 05:45:36
Copyright (c) Amazon Web Services
PostgreSQL 17.5 on aarch64-unknown-linux-gnu (Babelfish 5.2.0)

Msg 33557097, Level 16, State 1, Line 10
invalid regular expression: parentheses () not balanced
Msg 33557097, Level 16, State 1, Line 12
invalid regular expression: parentheses () not balanced

This works on MSSQL:

set nocount on
select @@version
select patindex('%(%','the phone Nr is 1-(800)-CARS') [left_par]
select patindex('%)%','the phone Nr is 1-(800)-CARS') [right_par]

-------------------------------------------------------------------------------
Microsoft SQL Server 2022 (RTM-CU21) (KB5065865) - 16.0.4215.2 (X64) 
	Aug 11 2025 13:24:21 
	Copyright (C) 2022 Microsoft Corporation
	Developer Edition (64-bit) on Linux (Ubuntu 22.04.5 LTS) <X64>

left_par
-----------
19

right_par
-----------
23

Version

BABEL_5_X_DEV (Default)

Extension

None

Which flavor of Linux are you using when you see the bug?

No response

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions