phoenix_使用中遇到的问题(日期类型TypeMismatchException)

本文介绍在Phoenix数据库中正确插入日期类型的方法。当尝试使用字符串格式插入日期时,将触发TypeMismatchException异常。解决办法是使用TO_DATE函数进行转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

phoenixupsert date类型数据如下sql:

upsert into "test_date_type" (ID,"birthday") values (102, '2013-09-01 09:00:02');

执行时会有如下错误信息:

com.salesforce.phoenix.schema.TypeMismatchException: ERROR 203 (22005): Type mismatch. DATE and VARCHAR for 2013-09-01 09:00:02

    at com.salesforce.phoenix.expression.LiteralExpression.newConstant(LiteralExpression.java:126)

    at com.salesforce.phoenix.expression.LiteralExpression.newConstant(LiteralExpression.java:108)

    at com.salesforce.phoenix.compile.UpsertCompiler$UpsertValuesCompiler.visit(UpsertCompiler.java:633)

    at com.salesforce.phoenix.compile.UpsertCompiler$UpsertValuesCompiler.visit(UpsertCompiler.java:609)

    at com.salesforce.phoenix.parse.LiteralParseNode.accept(LiteralParseNode.java:70)

    at com.salesforce.phoenix.compile.UpsertCompiler.compile(UpsertCompiler.java:554)

    at com.salesforce.phoenix.jdbc.PhoenixStatement$ExecutableUpsertStatement.compilePlan(PhoenixStatement.java:290)

    at com.salesforce.phoenix.jdbc.PhoenixStatement$ExecutableUpsertStatement.optimizePlan(PhoenixStatement.java:295)

    at com.salesforce.phoenix.jdbc.PhoenixStatement$ExecutableUpsertStatement.executeUpdate(PhoenixStatement.java:279)

    at com.salesforce.phoenix.jdbc.PhoenixStatement$ExecutableUpsertStatement.execute(PhoenixStatement.java:272)

    at com.salesforce.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1014)>

 

通常在关系型数据库中我们可以用字符串来表示一个date类型,但是在phoenix中是不行的,会抛出TypeMismatchException: ERROR 203 (22005): Type mismatch. DATE and VARCHAR异常。

正确的做法是使用TO_DATE函数:

upsert into "test_date_type" (ID,"birthday") values (102, TO_DATE('2013-09-01 09:00:02'));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值