Impala - How to get the third to last occurrence of a character within a string
up vote
0
down vote
favorite
I've the following string:
SELECT '00000-AAA1-1111-BBBB1-010101-CCCC1' as Word
FROM Table_A
I have the above string I only want to extract the string between the third-to-last and the last occurence.
Basically, I want to extract the following string:
'BBBB1'
I was trying with that but it gives me the wrong result:
substr(Word, 1, length(a.cod_system_shipment_detail) - length(reverse(split_part(reverse(Word),'|',1))))
"00000-AAA1-1111-BBBB1-010101-"
How can extract only BBBB1 from the above string?
Thanks!
impala substr
add a comment |
up vote
0
down vote
favorite
I've the following string:
SELECT '00000-AAA1-1111-BBBB1-010101-CCCC1' as Word
FROM Table_A
I have the above string I only want to extract the string between the third-to-last and the last occurence.
Basically, I want to extract the following string:
'BBBB1'
I was trying with that but it gives me the wrong result:
substr(Word, 1, length(a.cod_system_shipment_detail) - length(reverse(split_part(reverse(Word),'|',1))))
"00000-AAA1-1111-BBBB1-010101-"
How can extract only BBBB1 from the above string?
Thanks!
impala substr
it is not clear what you are expecting. what do you mean third to last and last occurrence? I would suggest add some additional explanation
– hlagos
Nov 14 at 13:36
From "'00000-AAA1-1111-BBBB1-010101-CCCC1'" I want to extract BBBB1. Before 'BBBB1' we have 3 special characters and 2 after.
– Pedro Alves
Nov 14 at 15:05
before bbbb1 I see "1111-" not sure what you mean by specifial characters
– hlagos
Nov 14 at 15:08
special character: "-"
– Pedro Alves
Nov 14 at 16:27
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've the following string:
SELECT '00000-AAA1-1111-BBBB1-010101-CCCC1' as Word
FROM Table_A
I have the above string I only want to extract the string between the third-to-last and the last occurence.
Basically, I want to extract the following string:
'BBBB1'
I was trying with that but it gives me the wrong result:
substr(Word, 1, length(a.cod_system_shipment_detail) - length(reverse(split_part(reverse(Word),'|',1))))
"00000-AAA1-1111-BBBB1-010101-"
How can extract only BBBB1 from the above string?
Thanks!
impala substr
I've the following string:
SELECT '00000-AAA1-1111-BBBB1-010101-CCCC1' as Word
FROM Table_A
I have the above string I only want to extract the string between the third-to-last and the last occurence.
Basically, I want to extract the following string:
'BBBB1'
I was trying with that but it gives me the wrong result:
substr(Word, 1, length(a.cod_system_shipment_detail) - length(reverse(split_part(reverse(Word),'|',1))))
"00000-AAA1-1111-BBBB1-010101-"
How can extract only BBBB1 from the above string?
Thanks!
impala substr
impala substr
asked Nov 12 at 10:49
Pedro Alves
150111
150111
it is not clear what you are expecting. what do you mean third to last and last occurrence? I would suggest add some additional explanation
– hlagos
Nov 14 at 13:36
From "'00000-AAA1-1111-BBBB1-010101-CCCC1'" I want to extract BBBB1. Before 'BBBB1' we have 3 special characters and 2 after.
– Pedro Alves
Nov 14 at 15:05
before bbbb1 I see "1111-" not sure what you mean by specifial characters
– hlagos
Nov 14 at 15:08
special character: "-"
– Pedro Alves
Nov 14 at 16:27
add a comment |
it is not clear what you are expecting. what do you mean third to last and last occurrence? I would suggest add some additional explanation
– hlagos
Nov 14 at 13:36
From "'00000-AAA1-1111-BBBB1-010101-CCCC1'" I want to extract BBBB1. Before 'BBBB1' we have 3 special characters and 2 after.
– Pedro Alves
Nov 14 at 15:05
before bbbb1 I see "1111-" not sure what you mean by specifial characters
– hlagos
Nov 14 at 15:08
special character: "-"
– Pedro Alves
Nov 14 at 16:27
it is not clear what you are expecting. what do you mean third to last and last occurrence? I would suggest add some additional explanation
– hlagos
Nov 14 at 13:36
it is not clear what you are expecting. what do you mean third to last and last occurrence? I would suggest add some additional explanation
– hlagos
Nov 14 at 13:36
From "'00000-AAA1-1111-BBBB1-010101-CCCC1'" I want to extract BBBB1. Before 'BBBB1' we have 3 special characters and 2 after.
– Pedro Alves
Nov 14 at 15:05
From "'00000-AAA1-1111-BBBB1-010101-CCCC1'" I want to extract BBBB1. Before 'BBBB1' we have 3 special characters and 2 after.
– Pedro Alves
Nov 14 at 15:05
before bbbb1 I see "1111-" not sure what you mean by specifial characters
– hlagos
Nov 14 at 15:08
before bbbb1 I see "1111-" not sure what you mean by specifial characters
– hlagos
Nov 14 at 15:08
special character: "-"
– Pedro Alves
Nov 14 at 16:27
special character: "-"
– Pedro Alves
Nov 14 at 16:27
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
If you want to split by -
and get the third element, you can do it as follow
SELECT split_part('00000-AAA1-1111-BBBB1-010101-CCCC1', '-',4);
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%2f53260563%2fimpala-how-to-get-the-third-to-last-occurrence-of-a-character-within-a-string%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
up vote
1
down vote
accepted
If you want to split by -
and get the third element, you can do it as follow
SELECT split_part('00000-AAA1-1111-BBBB1-010101-CCCC1', '-',4);
add a comment |
up vote
1
down vote
accepted
If you want to split by -
and get the third element, you can do it as follow
SELECT split_part('00000-AAA1-1111-BBBB1-010101-CCCC1', '-',4);
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
If you want to split by -
and get the third element, you can do it as follow
SELECT split_part('00000-AAA1-1111-BBBB1-010101-CCCC1', '-',4);
If you want to split by -
and get the third element, you can do it as follow
SELECT split_part('00000-AAA1-1111-BBBB1-010101-CCCC1', '-',4);
answered Nov 16 at 1:39
hlagos
3,5681817
3,5681817
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53260563%2fimpala-how-to-get-the-third-to-last-occurrence-of-a-character-within-a-string%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 is not clear what you are expecting. what do you mean third to last and last occurrence? I would suggest add some additional explanation
– hlagos
Nov 14 at 13:36
From "'00000-AAA1-1111-BBBB1-010101-CCCC1'" I want to extract BBBB1. Before 'BBBB1' we have 3 special characters and 2 after.
– Pedro Alves
Nov 14 at 15:05
before bbbb1 I see "1111-" not sure what you mean by specifial characters
– hlagos
Nov 14 at 15:08
special character: "-"
– Pedro Alves
Nov 14 at 16:27