在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'来自哪里?
- 什么是误解?