在MonetDB中混合使用Python和SQL是將大量業務邏輯移入數據庫服務器的一個很好的開始。然而,目前的文檔包含了一些新手在這個遊戲中需要承擔的一些障礙。考慮下面的函數:在MonetDB中處理Python UDF
sql>select * from getsourceattributes('tables');
+---------------+
| c |
+===============+
| id |
| name |
| schema_id |
| query |
| type |
| system |
| commit_action |
| access |
| temporary |
+---------------+
和下表來收集一些統計數據:
create table dummy(tbl string, col string, stat integer);
現在知道PTBL是一個numpy的陣列,我試過如下:
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;
};
和用
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'
- 不清楚't'來自哪裏?
- 什麼是誤解?