functions.txt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ======================================
  2. PostgreSQL specific database functions
  3. ======================================
  4. All of these functions are available from the
  5. ``django.contrib.postgres.functions`` module.
  6. .. currentmodule:: django.contrib.postgres.functions
  7. ``RandomUUID``
  8. ==============
  9. .. class:: RandomUUID()
  10. Returns a version 4 UUID.
  11. Usage example:
  12. .. code-block:: pycon
  13. >>> from django.contrib.postgres.functions import RandomUUID
  14. >>> Article.objects.update(uuid=RandomUUID())
  15. ``TransactionNow``
  16. ==================
  17. .. class:: TransactionNow()
  18. Returns the date and time on the database server that the current transaction
  19. started. If you are not in a transaction it will return the date and time of
  20. the current statement. This is a complement to
  21. :class:`django.db.models.functions.Now`, which returns the date and time of the
  22. current statement.
  23. Note that only the outermost call to :func:`~django.db.transaction.atomic()`
  24. sets up a transaction and thus sets the time that ``TransactionNow()`` will
  25. return; nested calls create savepoints which do not affect the transaction
  26. time.
  27. Usage example:
  28. .. code-block:: pycon
  29. >>> from django.contrib.postgres.functions import TransactionNow
  30. >>> Article.objects.filter(published__lte=TransactionNow())
  31. <QuerySet [<Article: How to Django>]>