title: How do I automate field declarations within postgres using an array?
body: <p>I am trying to create a series of fields ina postgres database that use the same functions in the same orders in a table and would like to know if there is some way to automate this using another function.</p>
  
  <p>The following is an example of my current sql and what I would like to be able to do is pass a function and array of [10,20] and have it output the same fields.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION f1(in1 integer, in2 integer) RETURNS integer AS '
  SELECT CASE
      WHEN in1is NULL THEN 0
      WHEN in1 ~ ''^[0-9]+$'' = ''f'' THEN 0
      WHEN in1 = transtech_target THEN 1
      ELSE 0
  END' LANGUAGE SQL;
  
  CREATE OR REPLACE FUNCTION f2(in1 integer, in2 integer) RETURNS integer AS '
  SELECT CASE
      WHEN in1 is NULL THEN 0
      ELSE 0
  END' LANGUAGE SQL;
  
  SELECT 
     f1(inf1, '10') AS f10,
     f2(inf2, '10') AS f10up,
     f2(inf3, '10') AS f10dn,
     f1(inf1, '20') AS f20,
     f2(inf2, '20') AS f20up,
     f2(inf3, '20') AS f20dn,
  FROM table;
  </code></pre>
  
  <p>Any ideas or thoughts?</p>