title: PostgreSQL ERROR: invalid input syntax for integer: "1e+06"
body: <p>The full error message is:</p>
  
  <blockquote>
  <pre><code>ERROR: invalid input syntax for integer: "1e+06"
  SQL state: 22P02
  Context: In PL/R function sample
  </code></pre>
  </blockquote>
  
  <p>The query I'm using is:</p>
  
  <pre><code>WITH a as
  (
   SELECT a.tract_id_alias,
       array_agg(a.pgid ORDER BY a.pgid) as pgids,
       array_agg(a.sample_weight_geo ORDER BY a.pgid) as block_weights
   FROM results_20161109.block_microdata_res_joined a
   WHERE a.tract_id_alias in (66772, 66773, 66785, 66802, 66805, 66806, 66813)
   AND a.bldg_count_res &gt; 0 
   GROUP BY a.tract_id_alias
  
  )
  SELECT NULL::INTEGER agent_id, 
       a.tract_id_alias,
       b.year,
      unnest(shared.sample(a.pgids, 
                         b.n_agents, 
                         1 * b.year, 
                         True, 
                         a.block_weights)
                         ) as pgid
  FROM a
  LEFT JOIN results_20161109.initial_agent_count_by_tract_res_11 b
  ON a.tract_id_alias = b.tract_id_alias
  ORDER BY b.year, a.tract_id_alias, pgid;
  </code></pre>
  
  <p>And the <code>shared.sample</code> function I'm using is:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION shared.sample(ids bigint[], size integer, seed integer DEFAULT 1, with_replacement boolean DEFAULT false, probabilities numeric[] DEFAULT NULL::numeric[])
    RETURNS integer[] AS
  $BODY$
      set.seed(seed)
      if (length(ids) == 1) {
          s = rep(ids,size)
      } else {
          s = sample(ids,size, with_replacement,probabilities)
      }
      return(s)
  $BODY$
    LANGUAGE plr VOLATILE
    COST 100;
  ALTER FUNCTION shared.sample(bigint[], integer, integer, boolean, numeric[])
    OWNER TO "server-superusers";
  </code></pre>
  
  <p>I'm pretty new to this stuff, so any help would be appreciated.</p>