How to create a daterange in PostgreSQL using Rails

2.5k views Asked by At

I'm using Rails 3.2.7 and Postgres 9.2 trying to create a daterange

Here's how I'm creating it

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

And here's the resulting query and the error:

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

How can I make this work?

1

There are 1 answers

1
sl_bug On BEST ANSWER

will be available in rails 4 if this pull request will be merged - https://github.com/rails/rails/pull/7345