![](/img/trans.png)
[英]OPENJSON collation in Azure Synapse causes a collation conflict error
[英]BigQuery Collation
如何在 BigQuery 中設置排序順序?
我想要這樣的東西
SELECT Place
FROM Locations
ORDER BY Place COLLATE "en_CA"
除了 COLLATE 是 BigQuery 中的保留字外,我找不到任何文檔。
BigQuery 正在按 [a..zA..Z] 順序對以下字符串進行排序:
例如
有沒有辦法讓 BigQuery 按 [aA..zZ] 順序排序?
以下示例適用於 BigQuery 標准 SQL
#standardSQL
create temp function collate_order(text string) as ((
select string_agg(chr(1000 * ascii(lower(c)) - ascii(c)), '' order by offset)
from unnest(split(text)) c with offset
));
with `project.dataset.Locations` as (
select 'ant' as Place union all
select 'Apple' union all
select 'bee' union all
select 'apple' union all
select 'cat' union all
select 'Banana' union all
select 'Cantaloupe'
)
select Place
from `project.dataset.Locations`
order by collate_order(Place)
output
忘記提及 - 顯然您可以通過將ascii
替換為unicode
function 來擴展此方法來處理 unicode 文本
您可以嘗試以下查詢,它將滿足您的要求,它將按 [aA..zZ] 順序對數據進行排序:-
SELECT Place
FROM Locations
ORDER BY upper(Place)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.