无法在 presto 中将 varbinary 转换为 varchar

Cannot cast varbinary to varchar in presto

我有一个在 varbinary 中的列。 我试过了

select cast(msg as varchar) 
from table 
WHERE DATE(datestr) > CURRENT_DATE - INTERVAL '7' DAY

哪个投了

Cannot cast row(row1 varbinary) to varchar

当我尝试时

from table 
WHERE DATE(datestr) > CURRENT_DATE - INTERVAL '7' DAY

我明白了

Unexpected parameters (row(row1 varbinary)) for function from_utf8. Expected: from_utf8(varbinary, varchar(x)) , from_utf8(varbinary, bigint) , from_utf8(varbinary) "

我也试过了,

select from_utf8(msg) 
from table 
WHERE DATE(datestr) > CURRENT_DATE - INTERVAL '7' DAY

哪个投了

Unexpected parameters (row(row1 varbinary)) for function from_utf8. Expected: from_utf8(varbinary, varchar(x)) , from_utf8(varbinary, bigint) , from_utf8(varbinary) "

我在网上尝试了几种方法,但似乎都没有用。谁能帮帮我?

基于异常 - msg 列不是 varbinary,而是 ROW,其中有一个 varbinary 字段名为 row1。您可以通过名称 (msg.row1):

使用字段引用运算符 . 访问它
-- sample data
WITH dataset (msg, id) AS (
    VALUES (cast(row (to_utf8(cast(now() as varchar))) as row(row1 varbinary)), 1)
)

-- query
select from_utf8(msg.row1) 
from dataset

输出:

_col0
2022-05-14 14:09:30.391 UTC