1. ======================================
    
  2. PostgreSQL specific database functions
    
  3. ======================================
    
  4. 
    
  5. All of these functions are available from the
    
  6. ``django.contrib.postgres.functions`` module.
    
  7. 
    
  8. .. currentmodule:: django.contrib.postgres.functions
    
  9. 
    
  10. ``RandomUUID``
    
  11. ==============
    
  12. 
    
  13. .. class:: RandomUUID()
    
  14. 
    
  15. Returns a version 4 UUID.
    
  16. 
    
  17. On PostgreSQL < 13, the `pgcrypto extension`_ must be installed. You can use
    
  18. the :class:`~django.contrib.postgres.operations.CryptoExtension` migration
    
  19. operation to install it.
    
  20. 
    
  21. .. _pgcrypto extension: https://www.postgresql.org/docs/current/pgcrypto.html
    
  22. 
    
  23. Usage example::
    
  24. 
    
  25.     >>> from django.contrib.postgres.functions import RandomUUID
    
  26.     >>> Article.objects.update(uuid=RandomUUID())
    
  27. 
    
  28. ``TransactionNow``
    
  29. ==================
    
  30. 
    
  31. .. class:: TransactionNow()
    
  32. 
    
  33. Returns the date and time on the database server that the current transaction
    
  34. started. If you are not in a transaction it will return the date and time of
    
  35. the current statement. This is a complement to
    
  36. :class:`django.db.models.functions.Now`, which returns the date and time of the
    
  37. current statement.
    
  38. 
    
  39. Note that only the outermost call to :func:`~django.db.transaction.atomic()`
    
  40. sets up a transaction and thus sets the time that ``TransactionNow()`` will
    
  41. return; nested calls create savepoints which do not affect the transaction
    
  42. time.
    
  43. 
    
  44. Usage example::
    
  45. 
    
  46.     >>> from django.contrib.postgres.functions import TransactionNow
    
  47.     >>> Article.objects.filter(published__lte=TransactionNow())
    
  48.     <QuerySet [<Article: How to Django>]>