本文介绍 django.db.models.Index.expressions 的用法。
声明
Index.expressions
Django 3.2 中的新函数。 
位置参数*expressions 允许在表达式和数据库函数上创建函数索引。
例如:
Index(Lower('title').desc(), 'pub_date', name='lower_title_date_idx')
以降序对title 字段的小写值创建索引,并以默认升序对pub_date 字段创建索引。
另一个例子:
Index(F('height') * F('weight'), Round('weight'), name='calc_idx')
为字段height 和weight 相乘的结果创建索引,并将weight 四舍五入到最接近的整数。
使用 *expressions 时需要   。Index.name 
对 Oracle 的限制
Oracle 要求将索引中引用的函数标记为 DETERMINISTIC 。 Django 不验证这一点,但 Oracle 会出错。这意味着不接受   等函数。Random() 
PostgreSQL 的限制
PostgreSQL 要求将索引中引用的函数和运算符标记为 IMMUTABLE 。 Django 不会验证这一点,但 PostgreSQL 会出错。这意味着不接受   等函数。Concat() 
MySQL 和 MariaDB
MySQL < 8.0.13 和 MariaDB 将忽略函数索引,因为它们都不支持。
相关用法
- Python Django Index.include用法及代码示例
 - Python Int转Bytes用法及代码示例
 - Python Django InlineModelAdmin.get_extra用法及代码示例
 - Python Django InlineModelAdmin.raw_id_fields用法及代码示例
 - Python InteractiveConsole runcode()用法及代码示例
 - Python InteractiveInterpreter runsource()用法及代码示例
 - Python InteractiveInterpreter runcode()用法及代码示例
 - Python IncrementalEncoder encode()用法及代码示例
 - Python Django InlineModelAdmin.get_max_num用法及代码示例
 - Python PIL Image.draft()用法及代码示例
 - Python PIL Image.thumbnail()用法及代码示例
 - Python PIL Image.new()用法及代码示例
 - Python PIL ImageOps.fit()用法及代码示例
 - Python Wand Image()用法及代码示例
 - Python PIL ImageDraw.Draw.rectangle()用法及代码示例
 - Python PIL ImageEnhance.Color() and ImageEnhance.Contrast()用法及代码示例
 - Python Itertools.zip_longest()用法及代码示例
 - Python PIL Image.getdata()用法及代码示例
 - Python Itertools.compress()用法及代码示例
 - Python PIL ImageFont.truetype()用法及代码示例
 - Python Itertools.count()用法及代码示例
 - Python PIL ImagePath.Path.tolist()用法及代码示例
 - Python PIL Image.transform()用法及代码示例
 - Python PIL Image.quantize()用法及代码示例
 - Python PIL Image.point()用法及代码示例
 
注:本文由纯净天空筛选整理自djangoproject.com大神的英文原创作品 django.db.models.Index.expressions。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
