PostgreSQL: Unable to drop a specific table named "user"
<p>I'm unable to delete a specific table in my PostgreSQL database. That table is called "user". When I try to run the snippet of code below,</p>

<pre><code>    import psycopg2
    conn = psycopg2.connect("dbname='mydatabase' user='postgres' host='localhost' password='mypassword'")
    cur = conn.cursor()
    cur.execute("DROP TABLE user;")  
    conn.commit()
    conn.close()
</code></pre>

<p>It spits out the following error</p>

<pre><code>  Traceback (most recent call last):
    File "dev_psycog.py", line 20, in &lt;module&gt;
       cur.execute("DROP TABLE user;")  
  psycopg2.ProgrammingError: syntax error at or near "user"
  LINE 1: DROP TABLE user;
</code></pre>

<p>I can delete any other table in my database just fine, but I can't seem to delete my table called "user". Is it because "user" is a <a href="https://www.postgresql.org/docs/7.3/static/sql-keywords-appendix.html" rel="nofollow">reserved keyword</a>?</p>

<p>Quote "user" as below</p>

<pre><code>import psycopg2
conn = psycopg2.connect("dbname='mydatabase' user='postgres' host='localhost' password='mypassword'")
cur = conn.cursor()
cur.execute('DROP TABLE "user";')  
conn.commit()
conn.close()
</code></pre>

<p>See <a href="https://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html" rel="nofollow">here</a>.</p>

<blockquote>
  <p>There is a second kind of identifier: the delimited identifier or
  quoted identifier. It is formed by enclosing an arbitrary sequence of
  characters in double-quotes (").</p>
</blockquote>

python sql postgresql psycopg2