You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).topic: operatorsFeatures & issues about comparing values inside of WHEREtype: bugDEPRECATED: replace with the "bug" issue type
On a side-note, this case also shows that we probably need to add a safeguard against update / delete with empty where clauses, for these cases where the where clause is interpreted incorrectly
@janmeier agree to add a safeguard against update / delete with empty where clauses.
Regarding the rest, in this case I chose JSON vs JSONB for reasons and would prefer not having to change it. On the other hand, the SO article you mentioned states:
There is no equality (or inequality) operator for the data type json as a whole.
I wish PostgreSQL offered a quick, easy way to check if the JSON is empty. It seems like it currently doesn't though, right?
My workaround in the end will probably be to keep another column as a "flag" boolean to know if the JSON is empty or not. I wish there was a more elegant solution, let me know if you find one.
@janmeier do you mean permanently changing the column data type from JSON to String, or going through each row, read the values and output them as text?
I'm experiencing the same issue, as I'm attempting to find a string in a JSON field. It returns the following error: operator does not exist: json ~~ unknown.
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).topic: operatorsFeatures & issues about comparing values inside of WHEREtype: bugDEPRECATED: replace with the "bug" issue type
Activity
janmeier commentedon Feb 12, 2016
Can't you just use
pensierinmusica commentedon Feb 12, 2016
@janmeier what you suggest seems to destroy all instances, and not just the ones with an empty JSON. Can you please check? Thx
janmeier commentedon Feb 12, 2016
Hmm, that's because
details: {}gives an empty where clause - definitely a bug.I think we need to add a special case to handle empty objects:
Note that both columns need to be cast to jsonb, since json does not support equality
janmeier commentedon Feb 12, 2016
Or we could cast to string or use
json_eachto count the number of props for something that also works without jsonb http://stackoverflow.com/questions/24292575/how-to-query-a-json-column-for-empty-objectsjanmeier commentedon Feb 12, 2016
On a side-note, this case also shows that we probably need to add a safeguard against update / delete with empty where clauses, for these cases where the
whereclause is interpreted incorrectlypensierinmusica commentedon Feb 12, 2016
@janmeier agree to add a safeguard against update / delete with empty
whereclauses.Regarding the rest, in this case I chose JSON vs JSONB for reasons and would prefer not having to change it. On the other hand, the SO article you mentioned states:
I wish PostgreSQL offered a quick, easy way to check if the JSON is empty. It seems like it currently doesn't though, right?
My workaround in the end will probably be to keep another column as a "flag" boolean to know if the JSON is empty or not. I wish there was a more elegant solution, let me know if you find one.
Thanks! Cheers
janmeier commentedon Feb 12, 2016
Should be possible to implement the empty check by casting the json to string though :-) (in sequelize, not in your own code)
pensierinmusica commentedon Feb 12, 2016
@janmeier do you mean permanently changing the column data type from JSON to String, or going through each row, read the values and output them as text?
janmeier commentedon Feb 12, 2016
No, you don't need to change anything, I'm saying that for this particular query we need to cast the field to a string to check whether it's empty
pensierinmusica commentedon Feb 29, 2016
Sure, this means though that you need to read each row in the db and can't keep an index, right?
pensierinmusica commentedon Jul 7, 2017
@janmeier why has this been closed?
GabeAtWork commentedon May 9, 2018
I'm experiencing the same issue, as I'm attempting to find a string in a
JSONfield. It returns the following error:operator does not exist: json ~~ unknown.That same query works fine on a
STRINGfield, though. I'm puzzled, as the docs specify that the field should be treated as plain string on PostgreSQL (which I'm using): http://docs.sequelizejs.com/manual/tutorial/querying.htmlI switched to
JSONBfor the purposes of filtering, as an alternative, but I do believe that the current JSON behavior is a bug.oaeide commentedon Sep 10, 2018
I have the same problem as @GabeAtWork
ephys commentedon Feb 25, 2023
#15598 implements this.
Produces