title: How to cast xpath's returning xml array to an int array in Postgres
body: <p>Is there a way to cast the returning XML array to an INT array when using xpath in Postgres 9.5? It appears to let me assign it to an INT array prior to using it but I cannot figure out how to use it directly in the where clause. Below is an example of how I am currently using it.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION people_get_by_ids(_xml XML)
  RETURNS SETOF people AS
  $$
  DECLARE
      _ids INT[] = (xpath('/ITEMS/ITEM/VALUE/text()', _xml));
  BEGIN
      RETURN QUERY
          SELECT *
          FROM people
          WHERE id = ANY(_ids);
  END
  $$ LANGUAGE plpgsql STABLE;
  </code></pre>
  
  <p>I would then call it like so</p>
  
  <pre><code>SELECT * FROM people_get_by_ids('&lt;ITEMS&gt;&lt;ITEM&gt;&lt;VALUE&gt;488&lt;/VALUE&gt;&lt;/ITEM&gt;&lt;ITEM&gt;&lt;VALUE&gt;489&lt;/VALUE&gt;&lt;/ITEM&gt;&lt;/ITEMS&gt;');
  </code></pre>
  
  <p>It would be nice if there was an simple and performant way to not use the _ids variable and just put the xpath part in the where clause.</p>
  
  <p>I need to do this in several places and plan on creating a function to wrap the <code>(xpath('/ITEMS/ITEM/VALUE/text()', _xml))</code> part in.</p>