title: Postgres PL/pgSQL, possible to declare anonymous custom types?
body: <p>With DB2 I'm able to declare anonymous custom types (e.g. row types or composite types) for my user defined functions - see the following example (especially the last line):</p>
  
  <p>DB2 example:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION myFunction(IN input1 DECIMAL(5), IN input2 DECIMAL(5)) 
      RETURNS DECIMAL(2) 
      READS SQL DATA 
      LANGUAGE SQL 
      NO EXTERNAL ACTION 
      NOT DETERMINISTIC
  BEGIN
    DECLARE TYPE customAnonymousType AS ROW(a1 DECIMAL(2), a2 DECIMAL(2), a3 DECIMAL(2));
    /* do something fancy... */
  </code></pre>
  
  <p>Can I do something similar with PL/pgSQL? I know I would be able to use existing row types, also existing user defined types - but do I really have to define the type in advance?</p>
  
  <p>I also know about the <em>RECORD</em> type, but as far as I understand I would not be able to use it in arrays (and also it would not be a well defined type).</p>
  
  <p>Comments asked for an example, even though it does lengthen the question a lot I tried to define a quite simple example (still for DB2):</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION myFunction(IN input1 DECIMAL(5), IN input2 DECIMAL(5)) 
      RETURNS DECIMAL(2) 
      READS SQL DATA 
      LANGUAGE SQL 
      NO EXTERNAL ACTION 
      NOT DETERMINISTIC
  BEGIN
    DECLARE TYPE customAnonymousType AS ROW(a1 DECIMAL(2), a2 CHARACTER VARYING(50));
    DECLARE TYPE customArray AS customAnonymousType ARRAY[INTEGER];
  
    DECLARE myArray customArray;
  
    SET myArray[input1] = (50, 'Product 1');
    SET myArray[input2] = (99, 'Product 2');
  
    RETURN myArray[ARRAY_FIRST(myArray)].a1;
  END
  </code></pre>
  
  <p>This function of course only serves as a dummy function (but I suppose it is already quite long for a question here). Actually it just decides which number to return depending on if <em>input1</em> is greater than <em>input2</em>. If <em>input1</em> is smaller than <em>input2</em>, it returns 50, if <em>input2</em> is smaller or equal than <em>input2</em> it would return 99.</p>
  
  <p>I know I'm not even using my <em>a2</em> character field of my type (so in this case I would also be able to just use an number array) and that there are probably many, many better solutions to return two fixed numbers depending on the input values, but still my original questions remains if I am able to use anonymous custom types in PL/pgSQL (as I would in Oracle or DB2 procedures) - or if there are any similar alternatives.</p>