How to pass field values as arguement to a stored procedure
<p>I have a DB table in which one column have an array of values.
Lets assume</p>

<pre><code>Student table
"Name" character(10),
"Subject_studying" text[],
</code></pre>

<p>I created a stored procedure as follows</p>

<pre><code>CREATE OR REPLACE FUNCTION ArrayLike(vals text[], v text) RETURNS integer AS $$
DECLARE
  str text;
BEGIN
  v := replace(replace(v, '%', '.*'), '_', '.');
  FOREACH str IN ARRAY vals LOOP
    IF str ~* v THEN
      RETURN 1;
    END IF;
  END LOOP;
  RETURN 0;
END; $$ 
LANGUAGE PLPGSQL;
</code></pre>

<p>Which returns all the subjects that I'm looking for.
How do I pass the parameter of the subjects to the stored procedure.</p>

<p>My query looks like</p>

<pre><code>SELECT Name FROM Student WHERE ArrayLike('Subject_studying', 'english') = 1
</code></pre>

<p>The query is giving me an error </p>

<pre><code> ERROR:  FOREACH expression must not be null
CONTEXT:  PL/pgSQL function Arraylike(text[],text) line 6 at FOREACH over array
********** Error **********
</code></pre>

<p>I guess the parameter 'Subject_studying' is not sent as a value but as a simple string. How do we pass the values in that field to the stored procedure?</p>