PG range insertion does not work with rom 5.1.1

Open
#343 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
postgresql, ruby
Domain
databases

Research direction

Start by running the linked pg_range.rb reproduction with bundle exec ruby and compare the four range inputs and their errors. Read the PostgreSQL range handling around ROM::SQL::Postgres::Values::Range, then review related issue #286. Done means creating a record with a PostgreSQL range column works for the supported range values.

Written by the indexing model from the issue text.

Description

bug

Creating record in table with pg range column does not work.

Example: https://github.com/cutalion/rom_experiments/blob/fdae88c28d7f5b59ccf9a40de8a4fc0916b9c2c5/pg_range.rb

def try(name)
  yield
  puts "#{name} works"
  rescue => e
    puts "#{name} does not work"
    puts e.message
  ensure
    puts
end


ruby_range = Range.new(Time.now, Time.now)
rom_range = ROM::SQL::Postgres::Values::Range.new(Time.now, Time.now)
sequel_range = Sequel::Postgres::PGRange.new(Time.now, Time.now)
custom_range = CustomRange.new(Time.now, Time.now)

try(:ruby_range) { pg_ranges.changeset(:create, range: ruby_range).commit }
try(:sequel_range) { pg_ranges.changeset(:create, range: sequel_range).commit }
try(:rom_range) { pg_ranges.changeset(:create, range: rom_range).commit }
try(:custom_range) { pg_ranges.changeset(:create, range: custom_range).commit }

Output:

$ bundle exec ruby pg_range.rb
ruby_range does not work
2019-08-15 19:37:25 +0300..2019-08-15 19:37:25 +0300 (Range) has invalid type for :range violates constraints (undefined method `exclude_begin?' for 2019-08-15 19:37:25 +0300..2019-08-15 19:37:25 +0300:Range
Did you mean?  exclude_end? failed)

sequel_range does not work
#<Sequel::Postgres::PGRange:0x000055f59c094448 @begin=2019-08-15 19:37:25 +0300, @end=2019-08-15 19:37:25 +0300, @empty=false, @exclude_begin=false, @exclude_end=false, @db_type=nil> (Sequel::Postgres::PGRange) has invalid type for :range violates constraints (undefined method `lower' for #<Sequel::Postgres::PGRange:0x000055f59c094448> failed)

rom_range does not work
"[2019-08-15 19:37:25 +0300,2019-08-15 19:37:25 +0300)" (String) has invalid type for :range violates constraints (undefined method `exclude_begin?' for "[2019-08-15 19:37:25 +0300,2019-08-15 19:37:25 +0300)":String failed)

custom_range does not work
"[2019-08-15 19:37:25 +0300,2019-08-15 19:37:25 +0300]" (String) has invalid type for :range violates constraints (undefined method `exclude_begin?' for "[2019-08-15 19:37:25 +0300,2019-08-15 19:37:25 +0300]":String failed)

This issue may be related to #286 (ruby ranges not working), but with latest rom/dry updates even ROM::SQL::Postgres::Values::Range does not work.

Dominant language
Ruby
Stars
220
Forks
97
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rom-rb/rom-sql

All issues in rom-rb/rom-sql

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.