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