2012/2/9 asmcos (SoSE) <asm...@gmail.com>:
> --
> mail list: http://groups.google.com/group/uliweb
> project : http://code.google.com/p/uliweb
2012/2/9 asmcos (SoSE) <asm...@gmail.com>:
怎么个重复法,你可以打开
[ORM]
DEBUG_LOG = True
在控制台看一下输出的sql语句是否正确,并且可以在数据库工具中直接输入对 应的Sql语句看是否不会重复?
--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://code.google.com/p/uliweb/
My Blog: http://hi.baidu.com/limodou
增加了 DEBUG_LOG=True;浏览主页没有发现SQL语句?我看你的文档中写的是查看日志。下面的信息是否是你说的日志?还是说有个其他的log文件?
distinct要添加字段列表,你的是空的,要把email加进去吧。
DEBUG_LOG会输出到控制台,会不会是在apache下的access.log中?
SELECT DISTINCT(column),column1,column2,... FROM tb_name
我参考的这篇文章
http://www.5idev.com/p-php_mysql_distinct.shtml
你说sqlalchemy的接口在变,能否提供url看一下?
我又查了一下,distinct应该可以算是有两种用法,一种是对返回所有字段作distinct处理,因此这种情况下相当于是
select distinct field1, field2 from table
因此Model.all().distinct()会在最前面加上distinct关键字,但是把所有字段列在后面。因此,如果只想显示个别字段,则可以使用values(),如:
Model.all().distinct().values(Model.c.field1, Model.c.field2)
但上面的处理是对于整条记录作了distinct处理,因此对于想混和有distinct字段和无distinct的字段时,可使用func.distinct函数,同时结合values,如:
Model.all().values(func.distinct(Model.c.field1), Model.c.field2)
这样生成的结果就是:
select distinct(field1), field2 from table
因此这种处理应该可以满足你的要求。
2012/2/10 asmcos (SoSE) <asm...@gmail.com>:
> 0.5.8 版本:我又查了一下,distinct应该可以算是有两种用法,一种是对返回所有字段作distinct处理,因此这种情况下相当于是
> /sqlalchemy$ vim sql/expression.py
>
> def distinct(expr):
> """Return a ``DISTINCT`` clause."""
> expr = _literal_as_binds(expr)
> return _UnaryExpression(expr, operator=operators.distinct_op,
> type_=expr.type)
>
>
>
> 0.6.4 版本:
> /sqlalchemy$ vim sql/expression.py
> @_generative
> def distinct(self):
> """return a new select() construct which will apply DISTINCT to its
> columns clause.
>
> """
> self._distinct = True
>
select distinct field1, field2 from table
因此Model.all().distinct()会在最前面加上distinct关键字,但是把所有字段列在后面。因此,如果只想显示个别字段,则可以使用values(),如:
Model.all().distinct().values(Model.c.field1, Model.c.field2)
但上面的处理是对于整条记录作了distinct处理,因此对于想混和有distinct字段和无distinct的字段时,可使用func.distinct函数,同时结合values,如:
Model.all().values(func.distinct(Model.c.field1), Model.c.field2)
这样生成的结果就是:
select distinct(field1), field2 from table
因此这种处理应该可以满足你的要求。
--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://code.google.com/p/uliweb/
My Blog: http://hi.baidu.com/limodou
0.5.8版本太低了,至少0.6以上版本。可以考虑使用0.7版本,不过最新的0.7.5好象有点问题。
使用func.distinct会自动生成distinct(column)的形式,所以按道理来说,使用values就可以实现你说的要求的。你可以看一下生成的sql是什么样子。