Skip to content

Parse error when order by clause is used inside JSON_ARRAYAGG #159

@abhijeet-pagi

Description

@abhijeet-pagi

Version - 170.100.0

Parser - TSql170Parser

When order by clause is used inside JSON_ARRAYAGG it does not get parsed with above mentioned parser version and details.

Steps to reproduce -

Try parsing the below SQL script with the parser:

SELECT TOP(5) c.object_id, JSON_ARRAYAGG(c.name ORDER BY c.column_id) AS column_list
FROM sys.columns AS c
GROUP BY c.object_id;

Note : Example used is available on Microsoft documentation here
Example -

    static void Main(string[] args)
    {
        var script = "<Example Script>";

        var parser = new TSql170Parser(true, 0);
        var fragment = parser.Parse(new StringReader(script), out var parseErrors);

        if (parseErrors.Count > 0)
        {
            Console.WriteLine(parseErrors[0].Message);
        }
    }

Error message :-

Incorrect syntax near 'ORDER'.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions