title: PostgreSQL add each item to list - DB functions
body: <p>I'd like to create a DB function that will accept a list of numbers and return a list of numbers. For each item in the list that was passed to the function, it should check some condition and add it to the response list. However, I don't think the way I am trying to do it is really a correct one. What I tried writing is basically some pseudo code here.</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION map_numbers(numbers integer[])
  returns integer[]
  AS 
  $BODY$
     DECLARE return_list integer[];
  
     FOREACH field IN ARRAY numbers LOOP
        CASE
           WHEN field = 3 THEN -- add 43 (this was a random thought, but I am basically trying to map a few of the numbers to different values)
        END
     END LOOP;
  
  RETURN QUERY SELECT * FROM return_list;
  $BODY$
    LANGUAGE sql VOLATILE
    COST 100;
  </code></pre>