functions.txt 1.5 KB

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