PostgreSQL 特有数据库函数¶
所有这些函数都可以从 django.contrib.postgres.function 模块中获得。
RandomUUID¶
返回一个版本 4 的 UUID。
用法示例:
>>> from django.contrib.postgres.functions import RandomUUID
>>> Article.objects.update(uuid=RandomUUID())
TransactionNow¶
返回数据库服务器上当前事务开始的日期和时间。如果你不在事务中,它将返回当前语句的日期和时间。这是对 django.db.models.function.Now 的补充,后者返回当前语句的日期和时间。
Note that only the outermost call to atomic()
sets up a transaction and thus sets the time that TransactionNow() will
return; nested calls create savepoints which do not affect the transaction
time.
用法示例:
>>> from django.contrib.postgres.functions import TransactionNow
>>> Article.objects.filter(published__lte=TransactionNow())
<QuerySet [<Article: How to Django>]>