简体   繁体   English

Bigquery 中的“TRIM”

[英]"TRIM" in Bigquery

I have the "state" column in the table.我在表中有“状态”列。 In this state column, when I checked the length of values, I found one cell only showing value 3 remaining all are 2. "OH" in the state column.在 state 列中,当我检查值的长度时,我发现一个单元格只显示值 3,其余均为 2。 state 列中的“OH”。 So it may be because of the space("OH ").所以可能是因为空格(“OH”)。 So I want to remove the space using the TRIM function.所以我想使用 TRIM function 删除空间。

在此处输入图像描述

Still, after running, The length shows "3" for the particular one.尽管如此,在运行之后,长度显示为特定的“3”。 If trims have happened, It should be shown 2 instead of 3. Why does this happen?如果发生修剪,应该显示 2 而不是 3。为什么会发生这种情况?

You should use LENGTH(TRIM(state)) if you want the length without blank spaces at the beginning or the end of state .如果您希望长度在state的开头或结尾没有空格,则应使用LENGTH(TRIM(state)) Notice that LENGTH(" OH") is still 3, although in your WHERE , LENGHT(TRIM(" OH") = LENGTH("OH") and that is 2, so " OH" passes your where condition.请注意, LENGTH(" OH")仍然是 3,尽管在您的WHERE中, LENGHT(TRIM(" OH") = LENGTH("OH")是 2,因此“OH”通过了您的 where 条件。

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

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