Do you have a comment or suggestion to improve SQL Server? We’d love to hear it!

Escaped, open square bracket '[[' not decoded - Microsoft.SqlServer.TransactSql.ScriptDom.Identifier.DecodeIdentifier()

Actual behavior:
Microsoft.SqlServer.TransactSql.ScriptDom.Identifier.DecodeIdentifier("[[[As]]]", out _) == "[[As]"

Expected behavior
Microsoft.SqlServer.TransactSql.ScriptDom.Identifier.DecodeIdentifier("[[[As]]]", out _) == "[As]"

Obviously Replace("[[", "[") is missing when decoding an identifier with QuoteType.SquareBracket

Microsoft.SqlServer.TransactSql.ScriptDom 14.0.3811.1

2 votes
Sign in
(thinking…)
Password icon
Signed in as (Sign out)

We’ll send you updates on this idea

Niklas Peter shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

2 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Solomon Rutzky commented  ·   ·  Flag as inappropriate

    P.S. I am only voting for this issue because this horrible UserVoice system does not provide any other mechanism for getting notifications for changes or comments on items you did not submit 😾 .

  • Solomon Rutzky commented  ·   ·  Flag as inappropriate

    Hello Niklas. You are misunderstanding how square brackets are escaped in delimited identifiers that use square brackets as the delimiter. It is _only_ the right square brackets that are escaped; left square brackets are _not_ escaped. Hence, the "actual behavior" is correct, and the "expected behavior" is an invalid expectation.

    For example, the following query:
    --------------------------------------------------------------
    SELECT 1 AS [[[As]]], 2 AS [[[[[Bt]]]]];
    --------------------------------------------------------------

    returns:
    --------------------------------------------------------------
    [[As] ..... [[[[Bt]]
    1 ............ 2
    --------------------------------------------------------------

    For a comprehensive list of rules describing how identifiers behave, please see:

    "Completely Complete List of Rules for T-SQL Identifiers" ( https://sqlquantumleap.com/reference/completely-complete-list-of-rules-for-t-sql-identifiers )

    This item is a non-issue and can be closed.

    Take care,
    Solomon ( https://SqlQuantumLeap.com/ )
    SQL# SQLCLR Library ( https://SQLsharp.com/ )

Feedback and Knowledge Base