rails postgres错误:双精度类型的输入语法无效 [英] rails postgres ERROR: invalid input syntax for type double precision

查看:859
本文介绍了rails postgres错误:双精度类型的输入语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下操作:

  user_calendars.where( extract(day from time_from)=?,next_day )

但我一直收到此错误:

  PG :: InvalidTextRepresentation:错误:双精度类型的输入语法无效:星期六第1行:... user_id = $ 1 AND(提取(从time_from开始的天)='星期六'... 

不确定为什么指出类型为double。

解决方案

在PostgreSQL中,表达式 extract(day from time_from)返回一个double类型的数字,表示星期六显然不是有效的双精度值。



如果需要其中的参数, )匹配字符串 Saturday(匹配星期几),然后使用 to_char()函数。

  user_calendars.where( trim(to_char(time_from,'Day'))=?,next_day)

您需要 trim(),因为对 to_char()的这种调用被填充为9个字符。 / p>

大小写对于参数'Day'是有意义的。如果将其键入为 day,则返回的值将与 Saturday不匹配。相反,类似 to_char(time_from,'day')的表达式将返回类似'saturday'的东西。


i'm trying the following:

user_calendars.where("extract(day from time_from) = ? ", next_day)

But i keep getting this Error:

PG::InvalidTextRepresentation: ERROR:  invalid input syntax for type double precision: "Saturday" LINE 1: ..."user_id" = $1 AND (extract(day from time_from) = 'Saturday'...

Not sure why it points out type double.

解决方案

In PostgreSQL, the expression extract(day from time_from) returns a number of type double, representing the day of the month. Saturday is clearly not a valid double.

If you need the argument to where() to match the string 'Saturday' (to match the day of the week), then use the to_char() function.

user_calendars.where("trim(to_char(time_from, 'Day')) = ? ", next_day)

You need trim(), because this kind of call to to_char() is padded to 9 characters.

Case is significant for the argument 'Day'. If you key it as 'day', the returned value won't match 'Saturday'. Instead, an expression like to_char(time_from, 'day') will return something like 'saturday'.

这篇关于rails postgres错误:双精度类型的输入语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆