{"title":"PostgreSQL specific lookups","version":"1.9","locale":"en","docname":"ref/contrib/postgres/lookups","url":"/en/1.9/ref/contrib/postgres/lookups/","canonical":"https://djangodocs.dev/en/1.9/ref/contrib/postgres/lookups/","summary":"Unaccent Link to this heading # The unaccent lookup allows you to perform accent-insensitive lookups using a dedicated PostgreSQL extension. This lookup is…","html":"<h1>PostgreSQL specific lookups<a class=\"heading-anchor\" href=\"#postgresql-specific-lookups\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"unaccent\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">Unaccent</span></code><a class=\"heading-anchor\" href=\"#unaccent\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p id=\"std-fieldlookup-unaccent\">The <code class=\"docutils literal notranslate\"><span class=\"pre\">unaccent</span></code> lookup allows you to perform accent-insensitive lookups using\na dedicated PostgreSQL extension.</p>\n<p>This lookup is implemented using <a class=\"reference internal\" href=\"/en/1.9/ref/models/lookups/#django.db.models.Transform\" title=\"django.db.models.Transform\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Transform</span></code></a>, so it\ncan be chained with other lookup functions. To use it, you need to add\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.postgres'</span></code> in your <a class=\"reference internal\" href=\"/en/1.9/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> and activate\nthe <a class=\"reference external\" href=\"http://www.postgresql.org/docs/current/interactive/unaccent.html\">unaccent extension on PostgreSQL</a>. The\n<a class=\"reference internal\" href=\"/en/1.9/ref/contrib/postgres/operations/#django.contrib.postgres.operations.UnaccentExtension\" title=\"django.contrib.postgres.operations.UnaccentExtension\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">UnaccentExtension</span></code></a> migration\noperation is available if you want to perform this activation using migrations).</p>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">unaccent</span></code> lookup can be used on\n<a class=\"reference internal\" href=\"/en/1.9/ref/models/fields/#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">CharField</span></code></a> and <a class=\"reference internal\" href=\"/en/1.9/ref/models/fields/#django.db.models.TextField\" title=\"django.db.models.TextField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">TextField</span></code></a>:</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=\"n\">City</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\">name__unaccent</span><span class=\"o\">=</span><span class=\"s2\">&quot;México&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">[&#39;&lt;City: Mexico&gt;&#39;]</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">User</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\">first_name__unaccent__startswith</span><span class=\"o\">=</span><span class=\"s2\">&quot;Jerem&quot;</span><span class=\"p\">)</span>\n<span class=\"go\">[&#39;&lt;User: Jeremy&gt;&#39;, &#39;&lt;User: Jérémy&gt;&#39;, &#39;&lt;User: Jérémie&gt;&#39;, &#39;&lt;User: Jeremie&gt;&#39;]</span>\n</code></pre></div>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">unaccent</span></code> lookups should perform fine in most use cases. However, queries\nusing this filter will generally perform full table scans, which can be slow\non large tables. In those cases, using dedicated full text indexing tools\nmight be appropriate.</p>\n</aside>\n</section>","rootId":"postgresql-specific-lookups","toc":[{"title":"Unaccent","anchor":"unaccent","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/en/1.9/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/en/1.9/ref/contrib/"},{"docname":"ref/contrib/postgres/index","title":"django.contrib.postgres","url":"/en/1.9/ref/contrib/postgres/"}],"prev":{"docname":"ref/contrib/postgres/functions","title":"PostgreSQL specific database functions","url":"/en/1.9/ref/contrib/postgres/functions/"},"next":{"docname":"ref/contrib/postgres/operations","title":"Database migration operations","url":"/en/1.9/ref/contrib/postgres/operations/"},"formats":{"html":"/en/1.9/ref/contrib/postgres/lookups/","markdown":"/en/1.9/ref/contrib/postgres/lookups.md","json":"/en/1.9/ref/contrib/postgres/lookups.json"},"source":"https://github.com/django/django/blob/stable/1.9.x/docs/ref/contrib/postgres/lookups.txt","official":"https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/lookups/","inVersions":["dev","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","1.8"],"inLocales":["en","fr","ja","id","pt-br","es"]}