In MySQL
, FIND_IN_SET
the function is used to find whether a value exists in a comma-separated list of strings. In PostgreSQL
, you can use string_to_array
the function to convert a comma-delimited string to an array, and then use ARRAY_POSITION
the function to find whether a value is in the array.
Here's how to convert a function MySQL
in FIND_IN_SET
to PostgreSQL
a function in :
MySQL query example:
SELECT FIND_IN_SET('value', 'value1,value2,value3');
Equivalent PostgreSQL query example:
SELECT CASE WHEN ARRAY_POSITION(string_to_array('value1,value2,value3', ','), 'value') IS NOT NULL THEN 'Found' ELSE 'Not Found' END;
In the above PostgreSQL
query, we first use string_to_array
the function to convert the comma separated string 'value1,value2,value3' into an array, and then use ARRAY_POSITION
the function to find whether 'value' is in the array. If the function returns a position other than NULL
, then the value was found.