How can i split column and group by in bigquery?
I has a SQL code in Legacy SQL was worked,
but in Standard SQL was wrong,
got the response:
Grouping by expressions of type ARRAY is not allowed
Is there any way can resolve ?
Here's my SQL code:
select tag
from
(
select SPLIT(content_tag, ',') as tag
from `test.log`
)
group by tag
sql
add a comment |
I has a SQL code in Legacy SQL was worked,
but in Standard SQL was wrong,
got the response:
Grouping by expressions of type ARRAY is not allowed
Is there any way can resolve ?
Here's my SQL code:
select tag
from
(
select SPLIT(content_tag, ',') as tag
from `test.log`
)
group by tag
sql
1
Please add an example of the input data and the expected result
– Ary Jazz
Nov 12 '18 at 8:09
Take a look at the following question in stackoverflow, it might help you: BigQuery: error in SPLIT() returns
– Mohammad Mohabbati
Nov 12 '18 at 8:41
add a comment |
I has a SQL code in Legacy SQL was worked,
but in Standard SQL was wrong,
got the response:
Grouping by expressions of type ARRAY is not allowed
Is there any way can resolve ?
Here's my SQL code:
select tag
from
(
select SPLIT(content_tag, ',') as tag
from `test.log`
)
group by tag
sql
I has a SQL code in Legacy SQL was worked,
but in Standard SQL was wrong,
got the response:
Grouping by expressions of type ARRAY is not allowed
Is there any way can resolve ?
Here's my SQL code:
select tag
from
(
select SPLIT(content_tag, ',') as tag
from `test.log`
)
group by tag
sql
sql
asked Nov 12 '18 at 7:46
Allen
41
41
1
Please add an example of the input data and the expected result
– Ary Jazz
Nov 12 '18 at 8:09
Take a look at the following question in stackoverflow, it might help you: BigQuery: error in SPLIT() returns
– Mohammad Mohabbati
Nov 12 '18 at 8:41
add a comment |
1
Please add an example of the input data and the expected result
– Ary Jazz
Nov 12 '18 at 8:09
Take a look at the following question in stackoverflow, it might help you: BigQuery: error in SPLIT() returns
– Mohammad Mohabbati
Nov 12 '18 at 8:41
1
1
Please add an example of the input data and the expected result
– Ary Jazz
Nov 12 '18 at 8:09
Please add an example of the input data and the expected result
– Ary Jazz
Nov 12 '18 at 8:09
Take a look at the following question in stackoverflow, it might help you: BigQuery: error in SPLIT() returns
– Mohammad Mohabbati
Nov 12 '18 at 8:41
Take a look at the following question in stackoverflow, it might help you: BigQuery: error in SPLIT() returns
– Mohammad Mohabbati
Nov 12 '18 at 8:41
add a comment |
3 Answers
3
active
oldest
votes
I think you are missing the [SAFE_OFFSET(1)] in your query, This should work
SELECT SPLIT(content_tag, ',') [SAFE_OFFSET(1)] AS tag
FROM `test.log`
GROUP BY tag
Edited for format code.
add a comment |
The legacy SQL query that you have provided will implicitly flatten the array returned from the SPLIT function, which is why it works. Using standard SQL, you need to be more explicit, however:
select tag
from `test.log`,
UNNEST(SPLIT(content_tag, ',')) as tag
group by tag
add a comment |
I am guessing you want something like this:
select tag, count(*)
from (select 'a b c' as tags union all
select 'd c'
) `test.log` cross join
unnest(split(tags, ' ')) tag
group by tag
order by count(*) desc;
This will count the number of tags in the space delimited list of tags.
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%2f53257778%2fhow-can-i-split-column-and-group-by-in-bigquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you are missing the [SAFE_OFFSET(1)] in your query, This should work
SELECT SPLIT(content_tag, ',') [SAFE_OFFSET(1)] AS tag
FROM `test.log`
GROUP BY tag
Edited for format code.
add a comment |
I think you are missing the [SAFE_OFFSET(1)] in your query, This should work
SELECT SPLIT(content_tag, ',') [SAFE_OFFSET(1)] AS tag
FROM `test.log`
GROUP BY tag
Edited for format code.
add a comment |
I think you are missing the [SAFE_OFFSET(1)] in your query, This should work
SELECT SPLIT(content_tag, ',') [SAFE_OFFSET(1)] AS tag
FROM `test.log`
GROUP BY tag
Edited for format code.
I think you are missing the [SAFE_OFFSET(1)] in your query, This should work
SELECT SPLIT(content_tag, ',') [SAFE_OFFSET(1)] AS tag
FROM `test.log`
GROUP BY tag
Edited for format code.
edited Nov 12 '18 at 9:02
انعام الرحمٰن
167112
167112
answered Nov 12 '18 at 8:45
Tamir Klein
939
939
add a comment |
add a comment |
The legacy SQL query that you have provided will implicitly flatten the array returned from the SPLIT function, which is why it works. Using standard SQL, you need to be more explicit, however:
select tag
from `test.log`,
UNNEST(SPLIT(content_tag, ',')) as tag
group by tag
add a comment |
The legacy SQL query that you have provided will implicitly flatten the array returned from the SPLIT function, which is why it works. Using standard SQL, you need to be more explicit, however:
select tag
from `test.log`,
UNNEST(SPLIT(content_tag, ',')) as tag
group by tag
add a comment |
The legacy SQL query that you have provided will implicitly flatten the array returned from the SPLIT function, which is why it works. Using standard SQL, you need to be more explicit, however:
select tag
from `test.log`,
UNNEST(SPLIT(content_tag, ',')) as tag
group by tag
The legacy SQL query that you have provided will implicitly flatten the array returned from the SPLIT function, which is why it works. Using standard SQL, you need to be more explicit, however:
select tag
from `test.log`,
UNNEST(SPLIT(content_tag, ',')) as tag
group by tag
answered Nov 12 '18 at 12:35
Elliott Brossard
16.1k21035
16.1k21035
add a comment |
add a comment |
I am guessing you want something like this:
select tag, count(*)
from (select 'a b c' as tags union all
select 'd c'
) `test.log` cross join
unnest(split(tags, ' ')) tag
group by tag
order by count(*) desc;
This will count the number of tags in the space delimited list of tags.
add a comment |
I am guessing you want something like this:
select tag, count(*)
from (select 'a b c' as tags union all
select 'd c'
) `test.log` cross join
unnest(split(tags, ' ')) tag
group by tag
order by count(*) desc;
This will count the number of tags in the space delimited list of tags.
add a comment |
I am guessing you want something like this:
select tag, count(*)
from (select 'a b c' as tags union all
select 'd c'
) `test.log` cross join
unnest(split(tags, ' ')) tag
group by tag
order by count(*) desc;
This will count the number of tags in the space delimited list of tags.
I am guessing you want something like this:
select tag, count(*)
from (select 'a b c' as tags union all
select 'd c'
) `test.log` cross join
unnest(split(tags, ' ')) tag
group by tag
order by count(*) desc;
This will count the number of tags in the space delimited list of tags.
answered Nov 12 '18 at 12:33
Gordon Linoff
758k35291399
758k35291399
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%2f53257778%2fhow-can-i-split-column-and-group-by-in-bigquery%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
1
Please add an example of the input data and the expected result
– Ary Jazz
Nov 12 '18 at 8:09
Take a look at the following question in stackoverflow, it might help you: BigQuery: error in SPLIT() returns
– Mohammad Mohabbati
Nov 12 '18 at 8:41