1

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.

Robin Garg
  • 203
  • 2
  • 13
  • Show the full, exact error message please. Edit the question then comment here when done. – Craig Ringer Sep 04 '15 at 07:22
  • There is no `find_in_set()` function in Postgres. Where in the manual did you find that? Also: you should **not** store comma separated values in a single column, that is really bad database design. –  Sep 04 '15 at 07:25

1 Answers1

2

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.