0
0

More than 3 years have passed since last update.

Active record search by JSON and JSONB column

Last updated at Posted at 2020-02-24

JSONB will helps lots to use PostgreSQL internal functions. But, if you have JSON column only then you need to cast like following.

  1. Array of Hashes

    column_name: [{a: 1}, {b: 2}, {c: 3}]

    Model.where('column_name::jsonb @> ', [{a: 1}].to_json)
    
  2. Select by json column and alias as Model method (TODO)

  3. Select by pattern and alias as object (TODO)

Reference:
https://www.postgresql.org/docs/current/functions-json.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0