【问题标题】:R, ClickHouse: Expected: FixedString(34). Got: UInt64: While processingR,ClickHouse:预期:FixedString(34)。得到:UInt64:处理时
【发布时间】:2020-12-07 19:20:24
【问题描述】:

我正在尝试从带有子集的 R 中查询 ClickHouse 数据库中的数据。 这是一个例子

library(data.table)
library(RClickhouse)
library(DBI)

subset <- paste(traffic[,unique(IDs)][1:30], collapse = ',')

conClickHouse <- DBI::dbConnect('here is the connection')


DataX <- dbgetdbGetQuery(conClickHouse, paste0("select * from database
                    and  IDs in (", subset ,") ", sep = "") )

结果我得到错误:

DB::Exception:IN 或 VALUES 部分中的类型不匹配。预期:FixedString(34)。 得到:UInt64: While processing (IDs IN ....

感谢任何帮助

感谢@DennyCrane 的评论,

"select * from database where toFixedString(IDs,34) in
     (toFixedString(ID1, 34), toFixedString(ID2,34 ))"

这个查询子集正确

【问题讨论】:

    标签: r dbi clickhouse


    【解决方案1】:

    https://clickhouse.tech/docs/en/sql-reference/functions/#strong-typing

    强类型

    与标准 SQL 相比,ClickHouse 具有强类型。换句话说,它不会在类型之间进行隐式转换。每个函数都适用于一组特定的类型。这意味着有时您需要使用类型转换函数。

    https://clickhouse.tech/docs/en/sql-reference/functions/type-conversion-functions/#tofixedstrings-n

    select * from (select 'x' B ) where B in (select toFixedString('x',1))
    DB::Exception: Types of column 1 in section IN don't match: String on the left, FixedString(1) on the right.
    

    使用强制转换为 toString 或 toFixedString

    select * from (select 'x' B ) where toFixedString(B,1) in (select toFixedString('x',1))

    【讨论】:

      猜你喜欢
      • 2020-11-25
      • 1970-01-01
      • 2021-04-29
      • 2018-11-12
      • 2018-01-22
      • 2019-06-12
      • 2017-03-16
      • 2018-12-04
      • 2020-03-04
      相关资源
      最近更新 更多