MySQL 5.6 ExtractValue XPath concat
I don't understand why extractvalue doesn't returns values of attributes when use MySQL concat function.
SET @xml = '<items>
<docHeader companyIdIssuer="company" docTypeId="2" companyIdReceiver="nin" dateIssue="2018-12-28">
<attribute attributeId="2" value="1236"/>
<docDetail productId="1" valor="some value">
<variable variableId="6" value="12.3" unitId="34"/>
<variable variableId="7" value="2.3" unitId="34"/>
<variable variableId="3" value="4.325" unitId="34"/>
<variable variableId="5" value="20" unitId="106"/>
<attribute attributeId="1" value="1236"/>
</docDetail>
</docHeader>
</items>';
SET @headerAttributePath = '//items/docHeader[1]/attribute[1]';
SET @detailPath = '//items/docHeader[1]/docDetail[1]';
SET @detailAttributePath = '//items/docHeader[1]/docDetail[1]/attribute[1]';
select extractValue(@xml, concat(@headerAttributePath, '/@attributeId')) AS attIdConcat,
extractValue(@xml, '//items/docHeader[1]/attribute[1]/@attributeId') AS attIdPlain,
extractValue(@xml, concat(@headerAttributePath, '/@value')) AS attValueConcat,
extractValue(@xml, '//items/docHeader[1]/attribute[1]/@value') AS attValuePlain,
@headerAttributePath AS attHeaderPath,
concat(@headerAttributePath, '/@value') AS attValuePathConcat,
'//items/docHeader[1]/attribute[1]/@value' AS attValuePathPlain,
STRCMP(concat(@headerAttributePath, '/@value'), '//items/docHeader[1]/attribute[1]/@value') AS pathStrComp,
extractValue(@xml, concat(@detailPath, '/@valor')) AS detValueConcat,
extractValue(@xml, concat(@detailAttributePath, '/@attributeId')) AS attDetIdConcat,
extractValue(@xml, concat(@detailAttributePath, '/@value')) AS attDetValueConcat;
Sample: SQL Fiddle
mysql xml xpath mysql-5.6
add a comment |
I don't understand why extractvalue doesn't returns values of attributes when use MySQL concat function.
SET @xml = '<items>
<docHeader companyIdIssuer="company" docTypeId="2" companyIdReceiver="nin" dateIssue="2018-12-28">
<attribute attributeId="2" value="1236"/>
<docDetail productId="1" valor="some value">
<variable variableId="6" value="12.3" unitId="34"/>
<variable variableId="7" value="2.3" unitId="34"/>
<variable variableId="3" value="4.325" unitId="34"/>
<variable variableId="5" value="20" unitId="106"/>
<attribute attributeId="1" value="1236"/>
</docDetail>
</docHeader>
</items>';
SET @headerAttributePath = '//items/docHeader[1]/attribute[1]';
SET @detailPath = '//items/docHeader[1]/docDetail[1]';
SET @detailAttributePath = '//items/docHeader[1]/docDetail[1]/attribute[1]';
select extractValue(@xml, concat(@headerAttributePath, '/@attributeId')) AS attIdConcat,
extractValue(@xml, '//items/docHeader[1]/attribute[1]/@attributeId') AS attIdPlain,
extractValue(@xml, concat(@headerAttributePath, '/@value')) AS attValueConcat,
extractValue(@xml, '//items/docHeader[1]/attribute[1]/@value') AS attValuePlain,
@headerAttributePath AS attHeaderPath,
concat(@headerAttributePath, '/@value') AS attValuePathConcat,
'//items/docHeader[1]/attribute[1]/@value' AS attValuePathPlain,
STRCMP(concat(@headerAttributePath, '/@value'), '//items/docHeader[1]/attribute[1]/@value') AS pathStrComp,
extractValue(@xml, concat(@detailPath, '/@valor')) AS detValueConcat,
extractValue(@xml, concat(@detailAttributePath, '/@attributeId')) AS attDetIdConcat,
extractValue(@xml, concat(@detailAttributePath, '/@value')) AS attDetValueConcat;
Sample: SQL Fiddle
mysql xml xpath mysql-5.6
It works in MySQL 8.0. Looks like a bug in 5.x that was fixed.
– Barmar
Dec 28 '18 at 21:04
add a comment |
I don't understand why extractvalue doesn't returns values of attributes when use MySQL concat function.
SET @xml = '<items>
<docHeader companyIdIssuer="company" docTypeId="2" companyIdReceiver="nin" dateIssue="2018-12-28">
<attribute attributeId="2" value="1236"/>
<docDetail productId="1" valor="some value">
<variable variableId="6" value="12.3" unitId="34"/>
<variable variableId="7" value="2.3" unitId="34"/>
<variable variableId="3" value="4.325" unitId="34"/>
<variable variableId="5" value="20" unitId="106"/>
<attribute attributeId="1" value="1236"/>
</docDetail>
</docHeader>
</items>';
SET @headerAttributePath = '//items/docHeader[1]/attribute[1]';
SET @detailPath = '//items/docHeader[1]/docDetail[1]';
SET @detailAttributePath = '//items/docHeader[1]/docDetail[1]/attribute[1]';
select extractValue(@xml, concat(@headerAttributePath, '/@attributeId')) AS attIdConcat,
extractValue(@xml, '//items/docHeader[1]/attribute[1]/@attributeId') AS attIdPlain,
extractValue(@xml, concat(@headerAttributePath, '/@value')) AS attValueConcat,
extractValue(@xml, '//items/docHeader[1]/attribute[1]/@value') AS attValuePlain,
@headerAttributePath AS attHeaderPath,
concat(@headerAttributePath, '/@value') AS attValuePathConcat,
'//items/docHeader[1]/attribute[1]/@value' AS attValuePathPlain,
STRCMP(concat(@headerAttributePath, '/@value'), '//items/docHeader[1]/attribute[1]/@value') AS pathStrComp,
extractValue(@xml, concat(@detailPath, '/@valor')) AS detValueConcat,
extractValue(@xml, concat(@detailAttributePath, '/@attributeId')) AS attDetIdConcat,
extractValue(@xml, concat(@detailAttributePath, '/@value')) AS attDetValueConcat;
Sample: SQL Fiddle
mysql xml xpath mysql-5.6
I don't understand why extractvalue doesn't returns values of attributes when use MySQL concat function.
SET @xml = '<items>
<docHeader companyIdIssuer="company" docTypeId="2" companyIdReceiver="nin" dateIssue="2018-12-28">
<attribute attributeId="2" value="1236"/>
<docDetail productId="1" valor="some value">
<variable variableId="6" value="12.3" unitId="34"/>
<variable variableId="7" value="2.3" unitId="34"/>
<variable variableId="3" value="4.325" unitId="34"/>
<variable variableId="5" value="20" unitId="106"/>
<attribute attributeId="1" value="1236"/>
</docDetail>
</docHeader>
</items>';
SET @headerAttributePath = '//items/docHeader[1]/attribute[1]';
SET @detailPath = '//items/docHeader[1]/docDetail[1]';
SET @detailAttributePath = '//items/docHeader[1]/docDetail[1]/attribute[1]';
select extractValue(@xml, concat(@headerAttributePath, '/@attributeId')) AS attIdConcat,
extractValue(@xml, '//items/docHeader[1]/attribute[1]/@attributeId') AS attIdPlain,
extractValue(@xml, concat(@headerAttributePath, '/@value')) AS attValueConcat,
extractValue(@xml, '//items/docHeader[1]/attribute[1]/@value') AS attValuePlain,
@headerAttributePath AS attHeaderPath,
concat(@headerAttributePath, '/@value') AS attValuePathConcat,
'//items/docHeader[1]/attribute[1]/@value' AS attValuePathPlain,
STRCMP(concat(@headerAttributePath, '/@value'), '//items/docHeader[1]/attribute[1]/@value') AS pathStrComp,
extractValue(@xml, concat(@detailPath, '/@valor')) AS detValueConcat,
extractValue(@xml, concat(@detailAttributePath, '/@attributeId')) AS attDetIdConcat,
extractValue(@xml, concat(@detailAttributePath, '/@value')) AS attDetValueConcat;
Sample: SQL Fiddle
mysql xml xpath mysql-5.6
mysql xml xpath mysql-5.6
asked Dec 28 '18 at 19:45
RenéRené
335
335
It works in MySQL 8.0. Looks like a bug in 5.x that was fixed.
– Barmar
Dec 28 '18 at 21:04
add a comment |
It works in MySQL 8.0. Looks like a bug in 5.x that was fixed.
– Barmar
Dec 28 '18 at 21:04
It works in MySQL 8.0. Looks like a bug in 5.x that was fixed.
– Barmar
Dec 28 '18 at 21:04
It works in MySQL 8.0. Looks like a bug in 5.x that was fixed.
– Barmar
Dec 28 '18 at 21:04
add a comment |
1 Answer
1
active
oldest
votes
A rather peculiar case, it seems that the combination of some paths, for example, items -> docHeader -> attribute -> @value
or items -> docHeader -> docDetail -> @valor
, produces errors in the parsing, which is a bug.
Some workarounds:
- If you can not change the name of any of the elements, you can use the CAST() function in CONCAT function.
- Rename one of the elements, for example,
docHeader
todoc_Header
,attribute
toattr
orvalor
to_valor
.
See db-fiddle.
As mentioned @Barmar, in MySQL 8.0, everything works as expected, see db-fiddle.
UPDATE
After some additional testing, we can see the problem also occurs when the total length of the path does not achieve a certain character length, see db-fiddle.
Thanks. I solved the problem using a short tag name "attr" plus CAST(… CHAR). I don't know if this definitely solves the problem, because XML have variable length. But, it's a good approach.
– René
Dec 31 '18 at 13:23
@René: In all my tests, the most reliable alternative wasCAST(... AS CHAR)
regardless of the length of the XML.
– wchiquito
Dec 31 '18 at 13:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963606%2fmysql-5-6-extractvalue-xpath-concat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
A rather peculiar case, it seems that the combination of some paths, for example, items -> docHeader -> attribute -> @value
or items -> docHeader -> docDetail -> @valor
, produces errors in the parsing, which is a bug.
Some workarounds:
- If you can not change the name of any of the elements, you can use the CAST() function in CONCAT function.
- Rename one of the elements, for example,
docHeader
todoc_Header
,attribute
toattr
orvalor
to_valor
.
See db-fiddle.
As mentioned @Barmar, in MySQL 8.0, everything works as expected, see db-fiddle.
UPDATE
After some additional testing, we can see the problem also occurs when the total length of the path does not achieve a certain character length, see db-fiddle.
Thanks. I solved the problem using a short tag name "attr" plus CAST(… CHAR). I don't know if this definitely solves the problem, because XML have variable length. But, it's a good approach.
– René
Dec 31 '18 at 13:23
@René: In all my tests, the most reliable alternative wasCAST(... AS CHAR)
regardless of the length of the XML.
– wchiquito
Dec 31 '18 at 13:40
add a comment |
A rather peculiar case, it seems that the combination of some paths, for example, items -> docHeader -> attribute -> @value
or items -> docHeader -> docDetail -> @valor
, produces errors in the parsing, which is a bug.
Some workarounds:
- If you can not change the name of any of the elements, you can use the CAST() function in CONCAT function.
- Rename one of the elements, for example,
docHeader
todoc_Header
,attribute
toattr
orvalor
to_valor
.
See db-fiddle.
As mentioned @Barmar, in MySQL 8.0, everything works as expected, see db-fiddle.
UPDATE
After some additional testing, we can see the problem also occurs when the total length of the path does not achieve a certain character length, see db-fiddle.
Thanks. I solved the problem using a short tag name "attr" plus CAST(… CHAR). I don't know if this definitely solves the problem, because XML have variable length. But, it's a good approach.
– René
Dec 31 '18 at 13:23
@René: In all my tests, the most reliable alternative wasCAST(... AS CHAR)
regardless of the length of the XML.
– wchiquito
Dec 31 '18 at 13:40
add a comment |
A rather peculiar case, it seems that the combination of some paths, for example, items -> docHeader -> attribute -> @value
or items -> docHeader -> docDetail -> @valor
, produces errors in the parsing, which is a bug.
Some workarounds:
- If you can not change the name of any of the elements, you can use the CAST() function in CONCAT function.
- Rename one of the elements, for example,
docHeader
todoc_Header
,attribute
toattr
orvalor
to_valor
.
See db-fiddle.
As mentioned @Barmar, in MySQL 8.0, everything works as expected, see db-fiddle.
UPDATE
After some additional testing, we can see the problem also occurs when the total length of the path does not achieve a certain character length, see db-fiddle.
A rather peculiar case, it seems that the combination of some paths, for example, items -> docHeader -> attribute -> @value
or items -> docHeader -> docDetail -> @valor
, produces errors in the parsing, which is a bug.
Some workarounds:
- If you can not change the name of any of the elements, you can use the CAST() function in CONCAT function.
- Rename one of the elements, for example,
docHeader
todoc_Header
,attribute
toattr
orvalor
to_valor
.
See db-fiddle.
As mentioned @Barmar, in MySQL 8.0, everything works as expected, see db-fiddle.
UPDATE
After some additional testing, we can see the problem also occurs when the total length of the path does not achieve a certain character length, see db-fiddle.
edited Dec 29 '18 at 12:06
answered Dec 29 '18 at 7:41
wchiquitowchiquito
11.7k22033
11.7k22033
Thanks. I solved the problem using a short tag name "attr" plus CAST(… CHAR). I don't know if this definitely solves the problem, because XML have variable length. But, it's a good approach.
– René
Dec 31 '18 at 13:23
@René: In all my tests, the most reliable alternative wasCAST(... AS CHAR)
regardless of the length of the XML.
– wchiquito
Dec 31 '18 at 13:40
add a comment |
Thanks. I solved the problem using a short tag name "attr" plus CAST(… CHAR). I don't know if this definitely solves the problem, because XML have variable length. But, it's a good approach.
– René
Dec 31 '18 at 13:23
@René: In all my tests, the most reliable alternative wasCAST(... AS CHAR)
regardless of the length of the XML.
– wchiquito
Dec 31 '18 at 13:40
Thanks. I solved the problem using a short tag name "attr" plus CAST(… CHAR). I don't know if this definitely solves the problem, because XML have variable length. But, it's a good approach.
– René
Dec 31 '18 at 13:23
Thanks. I solved the problem using a short tag name "attr" plus CAST(… CHAR). I don't know if this definitely solves the problem, because XML have variable length. But, it's a good approach.
– René
Dec 31 '18 at 13:23
@René: In all my tests, the most reliable alternative was
CAST(... AS CHAR)
regardless of the length of the XML.– wchiquito
Dec 31 '18 at 13:40
@René: In all my tests, the most reliable alternative was
CAST(... AS CHAR)
regardless of the length of the XML.– wchiquito
Dec 31 '18 at 13:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963606%2fmysql-5-6-extractvalue-xpath-concat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It works in MySQL 8.0. Looks like a bug in 5.x that was fixed.
– Barmar
Dec 28 '18 at 21:04