Fabricating hstore values for Postgresql

101 views
Skip to first unread message

Lucas Kulbacki

unread,
Sep 6, 2014, 3:52:47 PM9/6/14
to fabrica...@googlegroups.com
Hi!

As in title, I try to fabricate hash into hstore type column.

I found this (closed) issue: https://github.com/paulelliott/fabrication/issues/202, but syntax mentioned there does not help me.

My hstore column name is "status", there I want to set three flags: "processed", "duplicate", "eol". I'm using sequel (4.14.0) as ORM, fabrication (2.8.1), Ruby 2.1.2 and Postgresql of course ;)

case 1:
status {eol: true, duplicate: false, processed: true}
result: syntax error

case 2:
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
result: syntax error

case 3:
  status do
    {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
  end
result: 
Sequel::DatabaseError:
       PG::DatatypeMismatch: ERROR:  column "status" is of type hstore but expression is of type boolean
       LINE 1: ...23.0, '2000-01-01', (('heol' = '...
       HINT:  You will need to rewrite or cast the expression.

case 4:
  status do
    {status: "heol:true"}
  end
result:
Failure/Error: Fabricate(:entry)
     Sequel::DatabaseError:
       PG::UndefinedColumn: ERROR:  column "status" does not exist
       LINE 1: ...123.0, '2000-01-01', ("status" =...
       HINT:  There is a column named "status" in table "entries", but it cannot be referenced from this part of the query.

case 5:
  status do
    {'status' => "heol:true"}
  end
result:
    Failure/Error: Fabricate(:entry)
     Sequel::DatabaseError:
       PG::DatatypeMismatch: ERROR:  column "status" is of type hstore but expression is of type boolean
       LINE 1: ...123.0, '2000-01-01', ('status' =...
       HINT:  You will need to rewrite or cast the expression.

case 6:
gave up ;)
result:
this post

With FactoryGirl everything works as expected, and syntax is straightforward:
FactoryGirl.define do
  factory :entry do
    status {{ flag_processed: true, flag_duplicate: false }}
end

Promise to make good use of the correct syntax =)
Thanks!

Lucas.

Lucas Kulbacki

unread,
Sep 6, 2014, 4:04:34 PM9/6/14
to fabrica...@googlegroups.com

Paul Elliott

unread,
Sep 6, 2014, 4:13:55 PM9/6/14
to fabrica...@googlegroups.com
I just replied on Stack Overflow and am opening an issue to build in support for this so it works like you'd expect.



-- Paul


--
You received this message because you are subscribed to the Google Groups "fabrication" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabricationge...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages