{"title":"PostgreSQL specific database functions","version":"2.1","locale":"pt-br","docname":"ref/contrib/postgres/functions","url":"/pt-br/2.1/ref/contrib/postgres/functions/","canonical":"https://djangodocs.dev/pt-br/2.1/ref/contrib/postgres/functions/","summary":"All of these functions are available from the django.contrib.postgres.functions module. RandomUUID Link para este cabeçalho # class RandomUUID Link para esta…","html":"<h1>PostgreSQL specific database functions<a class=\"heading-anchor\" href=\"#postgresql-specific-database-functions\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>All of these functions are available from the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.postgres.functions</span></code> module.</p>\n<section id=\"randomuuid\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">RandomUUID</span></code><a class=\"heading-anchor\" href=\"#randomuuid\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.functions.RandomUUID\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">RandomUUID</span></span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.functions.RandomUUID\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<aside class=\"version-note version-added\" data-version=\"2.0\">\n<p class=\"version-note-title\">New in Django 2.0</p></aside>\n<p>Returns a version 4 UUID.</p>\n<p>The <a class=\"reference external\" href=\"https://www.postgresql.org/docs/current/static/pgcrypto.html\">pgcrypto extension</a> must be installed. You can use the\n<a class=\"reference internal\" href=\"/pt-br/2.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.CryptoExtension\" title=\"django.contrib.postgres.operations.CryptoExtension\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CryptoExtension</span></code></a> migration\noperation to install it.</p>\n<p>Usage example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.postgres.functions</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">RandomUUID</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">Article</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">update</span><span class=\"p\">(</span><span class=\"n\">uuid</span><span class=\"o\">=</span><span class=\"n\">RandomUUID</span><span class=\"p\">())</span>\n</code></pre></div>\n</section>\n<section id=\"transactionnow\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">TransactionNow</span></code><a class=\"heading-anchor\" href=\"#transactionnow\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.functions.TransactionNow\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">TransactionNow</span></span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.functions.TransactionNow\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Returns the date and time on the database server that the current transaction\nstarted. If you are not in a transaction it will return the date and time of\nthe current statement. This is a complement to\n<a class=\"reference internal\" href=\"/pt-br/2.1/ref/models/database-functions/#django.db.models.functions.Now\" title=\"django.db.models.functions.Now\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.db.models.functions.Now</span></code></a>, which returns the date and time of the\ncurrent statement.</p>\n<p>Note that only the outermost call to <a class=\"reference internal\" href=\"/pt-br/2.1/topics/db/transactions/#django.db.transaction.atomic\" title=\"django.db.transaction.atomic\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">atomic()</span></code></a>\nsets up a transaction and thus sets the time that <code class=\"docutils literal notranslate\"><span class=\"pre\">TransactionNow()</span></code> will\nreturn; nested calls create savepoints which do not affect the transaction\ntime.</p>\n<p>Usage example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.postgres.functions</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">TransactionNow</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">Article</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">filter</span><span class=\"p\">(</span><span class=\"n\">published__lte</span><span class=\"o\">=</span><span class=\"n\">TransactionNow</span><span class=\"p\">())</span>\n<span class=\"go\">&lt;QuerySet [&lt;Article: How to Django&gt;]&gt;</span>\n</code></pre></div>\n</section>","rootId":"postgresql-specific-database-functions","toc":[{"title":"RandomUUID","anchor":"randomuuid","children":[]},{"title":"TransactionNow","anchor":"transactionnow","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"Referência da API","url":"/pt-br/2.1/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/pt-br/2.1/ref/contrib/"},{"docname":"ref/contrib/postgres/index","title":"django.contrib.postgres","url":"/pt-br/2.1/ref/contrib/postgres/"}],"prev":{"docname":"ref/contrib/postgres/forms","title":"PostgreSQL specific form fields and widgets","url":"/pt-br/2.1/ref/contrib/postgres/forms/"},"next":{"docname":"ref/contrib/postgres/indexes","title":"PostgreSQL specific model indexes","url":"/pt-br/2.1/ref/contrib/postgres/indexes/"},"formats":{"html":"/pt-br/2.1/ref/contrib/postgres/functions/","markdown":"/pt-br/2.1/ref/contrib/postgres/functions.md","json":"/pt-br/2.1/ref/contrib/postgres/functions.json"},"source":"https://github.com/django/django/blob/stable/2.1.x/docs/ref/contrib/postgres/functions.txt","official":"https://docs.djangoproject.com/pt-br/2.1/ref/contrib/postgres/functions/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}