如何避免 Teradata 的 XMLCONCAT 和 XMLAGG 产生的额外空白
How to avoid extra whitespace produced by Teradata's XMLCONCAT and XMLAGG
当使用 XMLAGG
或 XMLCONCAT
时,Teradata 似乎在连接的内容之间添加了额外的空格:
with t (x) as (select 1)
select
xmlserialize(content xmlconcat(1, 2, 3) as varchar(1000)) a,
xmlserialize(content xmlagg(v order by v) as varchar(1000)) b
from (
select 1 from t
union all
select 2 from t
union all
select 3 from t
) as u (v)
以上产生:
|a |b |
|-----|-----|
|1 2 3|1 2 3|
有什么方法可以避免 XML 连接中的额外空白伪影并得到这个吗?
|a |b |
|---|---|
|123|123|
一个明显的 hack 是在连接过程中引入一个“不可能的”字符序列,然后再次从结果中删除它:
with t (x) as (select 1)
select
oreplace(
xmlserialize(content xmlconcat(1, '##', 2, '##', 3) as varchar(1000)),
' ## '
) a,
oreplace(
oreplace(
xmlserialize(content xmlagg(trim(v || '##') order by v) as varchar(1000)),
'## '
), '##'
) b
from (
select 1 from t
union all
select 2 from t
union all
select 3 from t
) as u (v)
现在的结果是:
|a |b |
|---|---|
|123|123|
当使用 XMLAGG
或 XMLCONCAT
时,Teradata 似乎在连接的内容之间添加了额外的空格:
with t (x) as (select 1)
select
xmlserialize(content xmlconcat(1, 2, 3) as varchar(1000)) a,
xmlserialize(content xmlagg(v order by v) as varchar(1000)) b
from (
select 1 from t
union all
select 2 from t
union all
select 3 from t
) as u (v)
以上产生:
|a |b |
|-----|-----|
|1 2 3|1 2 3|
有什么方法可以避免 XML 连接中的额外空白伪影并得到这个吗?
|a |b |
|---|---|
|123|123|
一个明显的 hack 是在连接过程中引入一个“不可能的”字符序列,然后再次从结果中删除它:
with t (x) as (select 1)
select
oreplace(
xmlserialize(content xmlconcat(1, '##', 2, '##', 3) as varchar(1000)),
' ## '
) a,
oreplace(
oreplace(
xmlserialize(content xmlagg(trim(v || '##') order by v) as varchar(1000)),
'## '
), '##'
) b
from (
select 1 from t
union all
select 2 from t
union all
select 3 from t
) as u (v)
现在的结果是:
|a |b |
|---|---|
|123|123|