Skip to content


DBAL-127: PostgreSQL: Quote "User" because it's a reserved word #1222

doctrinebot opened this Issue · 9 comments

4 participants


Jira issue originally created by user felicitus:

I have an entity "User" in D2-ORM which works fine on MySQL. However, when I tried to create the schema on PostgreSQL 9.0, it failed with the following error:

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "User"
^' in /usr/share/php/Doctrine/DBAL/Connection.php:577

The generated statement caused this was: CREATE TABLE User (id INT NOT NULL, username VARCHAR(50) NOT NULL, password VARCHAR(32) NOT NULL, admin BOOLEAN NOT NULL, PRIMARY KEY(id))

"User" needs to be quoted in order to work (I tested against PostgreSQL 9.0).


Comment created by @beberlei:

Doctrine does not do auto-escaping.

Please read the docs on quoting reserved words:


Issue was closed with resolution "Invalid"


Comment created by felicitus:

It's not that easy.

I can, of course, escape the table in the entity, e.g.

/*** @Entity @Table(name="User") **/

However, when using the SchemaTool, it will fail on the 2nd run because it tries to:


That fails, of course.

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this

how are things so far with this issue ?

Doctrine member

@samusenkoiv this issue is old and should be fixed already considering that USER is registered as reserved keyword in Doctrine and the platform explicitly quoting table names in getCreateTableSQL(). What issue are you having?


I've already found the way to define user table:
table: "`user`"

Thanks for your attention.

Doctrine member

@samusenkoiv you can do that by explicit quoting for sure but DBAL supports auto quoting reserved keywords. Can you please test if it works without quotes? If not, which statement(s) are failing? Because if this still is a bug, it needs our attention. Also please tell which DBAL version you are using. Thanks for your help!

@deeky666 deeky666 reopened this
@beberlei beberlei was unassigned by deeky666
@deeky666 deeky666 self-assigned this

You're right, I tried it with:
table: user
table: "user"
table: 'user'
And everything worked well, I probably made a mistake.
Thank for a fast feedback.

@deeky666 deeky666 added Fixed and removed Requires Feedback labels
Doctrine member

@samusenkoiv you're welcome. Thanks for investigating. Closing again as fixed, but as I do not know when it was fixes, no milestone attached.

@deeky666 deeky666 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.