-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Q: How to do search for JSONB column values? #277
Comments
I'd appreciate if anyone could clear out if it's possible to achieve search by data within JSONB column? In my example I have JSONB column |
Can you please try with the master branch of the repo? |
@matissg it seams master branch is okay. https://github.com/jbox-web/ajax-datatables-rails/blob/master/lib/ajax-datatables-rails/datatable/column.rb#L46 |
@ajahongir @n-rodriguez Thank you, I updated from master branch. |
The lambda waits for 2 params :
|
|
@n-rodriguez dont you think this feature shoud be in 0.4 branch? |
@ajahongir : yes, I'm doing some checks before releasing a v0.4.1 |
@n-rodriguez Thank you.
but now I get Update
gives me this error: |
@ajahongir Thank you, but I can't make it to work. I even tried this one, which was in another answer for JSON column:
but it's not working as well. |
whats is wrong with your case? |
@ajahongir Well, I have this error Basically I'm trying to filter records by drop-down string value of my |
def find_ptype
->(column, formatted_value) {
Arel.sql("JSON_EXTRACT(#{column.field}, '$.ptype') = #{formatted_value}")
}
end I think it should look like this. |
@ajahongir Ok, I got this error:
|
how should look like your right sql query? |
I could retrieve all "billboards" from "ptype" with this one: |
def find_ptype
->(column, formatted_value) {
Arel.sql("JSON_EXTRACT(#{column.field}, '$.ptype') = '#{formatted_value}'")
}
end how about this? |
Got this error:
|
@ajahongir In my model I have this scope:
and then the query looks like this:
As you see this part allows me to get my Do you have any other ideas of how should I change this? |
@ajahongir @n-rodriguez
I needed to add my table name before column and it seems it wasn't about Update If anyone needs here is how to do ILIKE search for JSONB column:
Query looks like this: |
Done! https://github.com/jbox-web/ajax-datatables-rails#tutorial Thank you! |
Thanks for the helpful thread. I ran into this myself and built upon this to find a cond function which may be more general. I have numerous fields in JSON. My cond filter
With this, I can define my view columns with whatever Postgres JSON magic needed. ajax-datatables-rails will just pass that magic as a string to the cond filter which will build the right SQL. Without this, the default behavior was that the magic was quoted as a single string in SQL, which gave a non-existent column error. My view_columns
|
I have
positions
table, where there is JSONB columndata
. I'm trying to search for values ofptype
inside thatdata
column.At the moment I can do sorting for
ptype
, however search is not working and I get this error:NoMethodError (undefined method "field" for "pilon":String):
when I search for "pillon" in myptype
field.My
ajax-datatables-rails
file looks like this:Search for my
name
column is working just fine since it's regular table column.For custom search I tried to copy idea from this example. How do I fix my search for JSONB column data, please?
The text was updated successfully, but these errors were encountered: