Skip to content

The xml .query() method fails to parse #67

Open

Description

@doron050

teesql version: v1.1.0 (5cd4b20)

Of the methods on an xml column, only .query() fails:

Expression Result
doc.value('(/order/@id)[1]', 'INT') ✅
doc.exist('/order') ✅
o.doc.nodes('/order/item') AS i(n) in CROSS APPLY ✅
doc.query('/order/item') ❌ unexpected token: query
SELECT doc.query('/order/item') FROM orders;

Expected: a function call on the column (FunctionCall with a CallTarget in SqlScriptDOM), like .value(). QUERY is probably lexed as a keyword after the .. That position is a method name, so any identifier, keywords included, should be accepted there.

Context: found by the SQL Server syntax matrix in sqlc-gen-csharp. The case (xml/xml_methods.sql):

CREATE TABLE orders_xml (id INT IDENTITY PRIMARY KEY, doc XML NOT NULL);

SELECT id, doc.value('(/order/@id)[1]', 'INT') AS order_id, doc.query('/order/item') AS items
FROM orders_xml WHERE doc.exist('/order[@status=sql:variable("@status")]') = 1;

SELECT o.id, i.n.value('@sku', 'NVARCHAR(20)') AS sku
FROM orders_xml o CROSS APPLY o.doc.nodes('/order/item') AS i(n);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions