问题
Query
select *
from inboxes
where find_in_set ('6',inboxes.to);
Above query i am using for accessing record from my table 'inboxes' having one of the column 'to' values like (2,4,6,7) string separated by commas. I am using find_in_set function in pg but it shows me error with below hint.
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
回答1:
You can simulate MySQL's find_in_set()
function using an array in Postgres.
select *
from inboxes
where '6' = any (string_to_array("to",','));
Note that to
is a reserved keyword and thus needs to be quoted "to"
. In general you should not reserved keywords as column names (or any other identifier)
But you should really think about fixing your data model. Your model is violating the first normal form and will give you many more headaches in the long run. One of the biggest problems is that you can't define any foreign key constraints on the values stored in that string value, or can you enforce any other constraints on the data.
来源:https://stackoverflow.com/questions/32391486/rails4-find-in-set-with-pg-not-working