title: Handling Python UDFs in MonetDB
body: <p>The blending of Python and SQL in MonetDB is a great start to move a lot of the business logic into the database server. However, the current documentation contains some hurdles to take by a novice in this game. Consider the following function:</p>
  
  <pre><code>sql&gt;select * from getsourceattributes('tables');
  +---------------+
  | c             |
  +===============+
  | id            |
  | name          |
  | schema_id     |
  | query         |
  | type          |
  | system        |
  | commit_action |
  | access        |
  | temporary     |
  +---------------+
  </code></pre>
  
  <p>and the following table to gather some stats:</p>
  
  <pre><code>create table dummy(tbl string, col string, stat integer);
  </code></pre>
  
  <p>Now knowing that ptbl is an numpy array, i tried the following:</p>
  
  <pre><code>create function gatherStatistics(ptbl string)
  returns string
  language python {
       for p in ptbl:
           attr = _conn.execute("select * from getSourceAttributes('"+ str(p) +"');")
           for col in attr :
               stat = _conn.execute("select count(*) from "+ str(p) +";")
               _conn_execute("insert into dummy values('"+ str(p)+"','"+ str(col) +"',"+ str(stat)+");")
       return ptbl;
  };
  </code></pre>
  
  <p>and calling with</p>
  
  <pre><code>select gatherstatistics('tables');
  SELECT: no such table 't'
  Python exception
     3.     attr = _conn.execute("select * from getSourceAttributes('"+ str(p) +"');")
     4.     for col in attr :
  
       5.       stat = _conn.execute("select count(*) from "+ str(p) +";")
  
     6.       _conn_execute("insert into dummy values('"+ str(p)+"','"+ str(col) +"',"+str(stat)+");")
     7.   return ptbl;
  SQL Query Failed: ParseException:SQLparser:42S02!SELECT: no such table 't'
  </code></pre>
  
  <ul>
  <li>unclear where the 't' comes from?</li>
  <li>what is the mis-conception?</li>
  </ul>