如何使用Rails在PostgreSQL中创建日期范围

时间:2012-09-11 22:05:49

标签: ruby-on-rails ruby-on-rails-3 postgresql postgresql-9.2 range-types

我正在使用Rails 3.2.7和Postgres 9.2尝试创建日期范围

以下是我创建它的方式

schedule_block              = ScheduleBlock.new
schedule_block.date_range   = [Date.new, Date.new]
schedule_block.save

这是结果查询和错误:

INSERT INTO "schedule_blocks" ("date_range") VALUES ($1) RETURNING "id"  [["date_range", [Mon, 01 Jan -4712, Mon, 01 Jan -4712]]]
PG::Error: ERROR:  malformed range literal: "---
- -4712-01-01
- -4712-01-01
"
DETAIL:  Missing left parenthesis or bracket.
: INSERT INTO "schedule_blocks" ("date_range") VALUES ($1) RETURNING "id"
   (0.1ms)  ROLLBACK
Completed 500 Internal Server Error in 496ms

我该如何做到这一点?

1 个答案:

答案 0 :(得分:7)

如果此拉取请求将合并,则

将在rails 4中可用 - https://github.com/rails/rails/pull/7345