AJcodez
AJcodez

Reputation: 34236

ruby sequel access json field

I have the following schema:

 Column  |            Type             |       Modifiers        
---------+-----------------------------+------------------------
 id      | text                        | not null
 data    | json                        | not null
 created | timestamp without time zone | not null default now()

If i open up psql i can run the query.

select id, data->'amount' as amount from plans;

But ruby sequel gem ruins it.

puts $db.run("select id, data->'amount' as amount from plans")

What's wrong?

Upvotes: 0

Views: 645

Answers (1)

AJcodez
AJcodez

Reputation: 34236

Needed #literal method.

$db.run("select id, data -> #{ $db.literal('amount') } as amount from plans")

Upvotes: 1

Related Questions