简体   繁体   English

条件插入xquery失败,错误为“意外插入,期望其他”

[英]Conditional insert xquery failing with error “unexpected insert, expecting else”

I am trying to execute the xquery on Sedna database to conditionally update the container, as below 我正在尝试在Sedna数据库上执行xquery以有条件地更新容器,如下所示

if(fn:exists(doc("blog")/entries/entry[@active="1" and @id="1"]/comments)) then
UPDATE insert <comment active="1"><name>sunil.s</name><email>suni.l.s@gmail.com</email><desc>desbbh</desc></comment> into doc("blog")/entries/entry[@active="1" and @id="1"]/comments
else
UPDATE insert <comments><comment active="1"><name>sunil.s</name><email>sunil.s@gmail.com</email><desc>sdd</desc></comment></comments> into doc("blog")/entries/entry[@active="1" and @id="1"]

But this query always failing with below error 但是此查询始终失败,并出现以下错误

SEDNA Message: ERROR XPST0003 It is a static error if an expression is not a valid instance of the grammar defined in A.1 EBNF. SEDNA消息:错误XPST0003如果表达式不是A.1 EBNF中定义的语法的有效实例,则为静态错误。 Details: at (2:8), syntax error, unexpected insert, expecting else 详细信息:在(2:8),语法错误,意外插入,期望其他

The error indicate that it is expecting else instead of insert in the second line. 该错误表明它正在期待else而不是在第二行中insert

Can someone please help me understand problem with the query and possible fix? 有人可以帮我了解查询问题和可能的解决方法吗?

Your query assumes the existence of an expression with syntax like 您的查询假设存在具有以下语法的表达式:

UPDATE insert expr into expr

There is no such expression in XQuery (or the XQuery Update Facility). XQuery(或XQuery Update Facility)中没有这样的表达式。 Instead, it appears to be a non-standard syntax supported by Sedna. 相反,它似乎是Sedn​​a支持的非标准语法。

However, the documentation ( http://www.sedna.org/progguide/ProgGuidesu6.html#x12-430002.3 ) refers to it as a "statement", not an "expression", suggesting that it must be the 'top-level' (outermost) construct in your query. 但是,文档( http://www.sedna.org/progguide/ProgGuidesu6.html#x12-430002.3 )将其称为“声明”,而不是“表达式”,表明它必须是“顶级” '(最外层)构造在您的查询中。

To accomplish this, you could rewrite your query as: 为此,您可以将查询重写为:

UPDATE
insert
    if ... then <comment>...</comment> else <comments>...</comments>
into
    if ... then doc("blog")/.../comments else doc("blog")/...

Unfortunately, this repeats the 'if' condition; 不幸的是,这重复了'if'条件; it's not clear whether Sedna provides a syntax for factoring that out, eg 尚不清楚Sedna是否提供了将其分解的语法,例如

UPDATE
let $c := ...
insert
    if $c then <comment>...</comment> else <comments>...</comments>
into
    if $c then doc("blog")/.../comments else doc("blog")/...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM