functions.txt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. The `pgcrypto extension`_ must be installed. You can use the
  13. :class:`~django.contrib.postgres.operations.CryptoExtension` migration
  14. operation to install it.
  15. .. _pgcrypto extension: https://www.postgresql.org/docs/current/static/pgcrypto.html
  16. Usage example::
  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. >>> from django.contrib.postgres.functions import TransactionNow
  33. >>> Article.objects.filter(published__lte=TransactionNow())
  34. <QuerySet [<Article: How to Django>]>