Django的SQL:没有这样的功能:十进制

时间:2018-09-01 04:11:01

标签: django

我有以下查询

RecipePosition.objects.all().filter(mass_quantity__gt=0)

在Django中,尝试调试文件/lib/python3.6/site-packages/django/db/models/sql/compiler.py,以了解sql的形成方式。

def execute_sql(self, result_type=MULTI, chunked_fetch=False, chunk_size=GET_ITERATOR_CHUNK_SIZE):
    """
    Run the query against the database and return the result(s). The
    return value is a single data item if result_type is SINGLE, or an
    iterator over the results if the result_type is MULTI.

    result_type is either MULTI (use fetchmany() to retrieve all rows),
    SINGLE (only retrieve a single row), or None. In this last case, the
    cursor is returned if any query is executed, since it's used by
    subclasses such as InsertQuery). It's possible, however, that no query
    is needed, as the filters describe an empty set. In that case, None is
    returned, to avoid any unnecessary database interaction.
    """
    result_type = result_type or NO_RESULTS
    try:
        sql, params = self.as_sql()
        if not sql:
            raise EmptyResultSet

在下面的语句中,我检查了sql和params:

sql, params = self.as_sql()


sql = SELECT "recipes_recipeposition"."id", 
             "recipes_recipeposition"."name",
             "recipes_recipeposition"."quantity", 
      FROM "recipes_recipeposition" 
      WHERE "recipes_recipeposition"."quantity" > %s

params = <class 'tuple'>: (Decimal('0'),)

我在sqlite浏览器中尝试了sql:

SELECT "recipes_recipeposition"."id", 
             "recipes_recipeposition"."name",
             "recipes_recipeposition"."quantity", 
      FROM "recipes_recipeposition" 
      WHERE "recipes_recipeposition"."quantity" > Decimal('0')

然后它说没有这样的功能:十进制

0 个答案:

没有答案