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:
sql>select * from getsourceattributes('tables');
+---------------+
| c |
+===============+
| id |
| name |
| schema_id |
| query |
| type |
| system |
| commit_action |
| access |
| temporary |
+---------------+
and the following table to gather some stats:
create table dummy(tbl string, col string, stat integer);
Now knowing that ptbl is an numpy array, i tried the following:
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;
};
and calling with
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'
- unclear where the 't' comes from?
- what is the mis-conception?