functions.txt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. On PostgreSQL < 13, the `pgcrypto extension`_ must be installed. You can use
  12. the :class:`~django.contrib.postgres.operations.CryptoExtension` migration
  13. operation to install it.
  14. .. _pgcrypto extension: https://www.postgresql.org/docs/current/pgcrypto.html
  15. Usage example:
  16. .. code-block:: pycon
  17. >>> from django.contrib.postgres.functions import RandomUUID
  18. >>> Article.objects.update(uuid=RandomUUID())
  19. ``TransactionNow``
  20. ==================
  21. .. class:: TransactionNow()
  22. Returns the date and time on the database server that the current transaction
  23. started. If you are not in a transaction it will return the date and time of
  24. the current statement. This is a complement to
  25. :class:`django.db.models.functions.Now`, which returns the date and time of the
  26. current statement.
  27. Note that only the outermost call to :func:`~django.db.transaction.atomic()`
  28. sets up a transaction and thus sets the time that ``TransactionNow()`` will
  29. return; nested calls create savepoints which do not affect the transaction
  30. time.
  31. Usage example:
  32. .. code-block:: pycon
  33. >>> from django.contrib.postgres.functions import TransactionNow
  34. >>> Article.objects.filter(published__lte=TransactionNow())
  35. <QuerySet [<Article: How to Django>]>