<p dir="auto"><strong>Migrated issue, originally created by jvanasco (<a href="https://github.com/jvanasco">@jvanasco</a>)</strong></p>
<p dir="auto">discussed previously in</p>
<ul dir="auto">
<li><a href="https://groups.google.com/forum/#!searchin/sqlalchemy/icontains/sqlalchemy/MUyt8zYaP0c/ht4fGR9q9w8J" rel="nofollow">https://groups.google.com/forum/#!searchin/sqlalchemy/icontains/sqlalchemy/MUyt8zYaP0c/ht4fGR9q9w8J</a></li>
<li><a href="https://groups.google.com/forum/#!searchin/sqlalchemy/icontains/sqlalchemy/331XoToT4lk/RPjIYNTkSEIJ" rel="nofollow">https://groups.google.com/forum/#!searchin/sqlalchemy/icontains/sqlalchemy/331XoToT4lk/RPjIYNTkSEIJ</a></li>
</ul>
<p dir="auto">I tried doing this myself, but don't know enough of the internals to get this done on my own.</p>
<p dir="auto">it looks like these need to be modified</p>
<ul dir="auto">
<li>sqlalchemy/sql/default_comparator.py</li>
<li>sqlalchemy/sql/operators.py</li>
</ul>
<p dir="auto">but not sure about</p>
<ul dir="auto">
<li>sqlalchemy/sql/compiler.py</li>
</ul>
<p dir="auto">there are probably more files.</p>
<p dir="auto">if someone can get one working, I can do the rest and build out tests.</p>
<h3 dir="auto">Describe the bug</h3>
<p dir="auto">Using MySQL 8.0.27 with a database table called <code class="notranslate">lead</code>.  Turns out this is a new reserved word in MariaDB.   I am using SQLAlchemy 1.3.24 and adding <code class="notranslate">lead</code> to your <code class="notranslate">dialects/mysql/base.py</code> <code class="notranslate">RESERVED_WORDS</code> set fixes the issue, causing the <code class="notranslate">lead</code> table to be escaped properly.  Looking at your latest 1.4.x branch, <code class="notranslate">lead</code> is not in there either.</p>
<p dir="auto">I know 1.3.24 is old, but still used in the industry.  If you could backport that reserved word in 1.3 that would be appreciated.</p>
<h3 dir="auto">To Reproduce</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Run a JOIN on a table called `leads` BUT the join alias is singular `lead` on MySQL 8.0.27.  An example SQL produced will be 

SELECT DISTINCT opportunities.id, opportunities.name, opportunities.lead_id, lead.id AS &quot;lead__id&quot;, lead.name
AS &quot;lead__name&quot;, lead.primary_contact_id AS &quot;lead__primary_contact_id&quot; FROM opportunities LEFT OUTER JOIN
leads AS lead ON opportunities.lead_id = lead.id;"><pre class="notranslate"><span class="pl-v">Run</span> <span class="pl-s1">a</span> <span class="pl-v">JOIN</span> <span class="pl-s1">on</span> <span class="pl-s1">a</span> <span class="pl-s1">table</span> <span class="pl-s1">called</span> <span class="pl-s">`leads`</span> <span class="pl-v">BUT</span> <span class="pl-s1">the</span> <span class="pl-s1">join</span> <span class="pl-s1">alias</span> <span class="pl-c1">is</span> <span class="pl-s1">singular</span> <span class="pl-s">`lead`</span> <span class="pl-s1">on</span> <span class="pl-v">MySQL</span> <span class="pl-c1">8.0</span><span class="pl-c1">.27</span>.  <span class="pl-v">An</span> <span class="pl-s1">example</span> <span class="pl-v">SQL</span> <span class="pl-s1">produced</span> <span class="pl-s1">will</span> <span class="pl-s1">be</span> 

<span class="pl-v">SELECT</span> <span class="pl-v">DISTINCT</span> <span class="pl-s1">opportunities</span>.<span class="pl-s1">id</span>, <span class="pl-s1">opportunities</span>.<span class="pl-s1">name</span>, <span class="pl-s1">opportunities</span>.<span class="pl-s1">lead_id</span>, <span class="pl-s1">lead</span>.<span class="pl-s1">id</span> <span class="pl-v">AS</span> <span class="pl-s">"lead__id"</span>, <span class="pl-s1">lead</span>.<span class="pl-s1">name</span>
<span class="pl-v">AS</span> <span class="pl-s">"lead__name"</span>, <span class="pl-s1">lead</span>.<span class="pl-s1">primary_contact_id</span> <span class="pl-v">AS</span> <span class="pl-s">"lead__primary_contact_id"</span> <span class="pl-v">FROM</span> <span class="pl-s1">opportunities</span> <span class="pl-v">LEFT</span> <span class="pl-v">OUTER</span> <span class="pl-v">JOIN</span>
<span class="pl-s1">leads</span> <span class="pl-v">AS</span> <span class="pl-s1">lead</span> <span class="pl-v">ON</span> <span class="pl-s1">opportunities</span>.<span class="pl-s1">lead_id</span> <span class="pl-c1">=</span> <span class="pl-s1">lead</span>.<span class="pl-s1">id</span>;</pre></div>
<p dir="auto">Which fails with <code class="notranslate">"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lead ON opportunities.lead_id = lead.id'</code> because <code class="notranslate">lead</code> is not escaped properly as it is not in your set of RESERVED words.</p>
<h3 dir="auto">Error</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lead ON opportunities.lead_id = lead.id'"><pre class="notranslate"><code class="notranslate">"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lead ON opportunities.lead_id = lead.id'
</code></pre></div>
<h3 dir="auto">Versions</h3>
<ul dir="auto">
<li>OS: Linux Manjaro</li>
<li>Python: 3.9.0</li>
<li>SQLAlchemy: 1.3.24</li>
<li>Database: MySQL 8.0.27</li>
<li>DBAPI (eg: psycopg, cx_oracle, mysqlclient): aiomysql via encode/databases</li>
</ul>
<h3 dir="auto">Additional context</h3>
<p dir="auto"><em>No response</em></p>