Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-127

PostgreSQL: Quote "User" because it's a reserved word

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 2.0.5
    • Fix Version/s: None
    • Component/s: Drivers
    • Labels:
      None

      Description

      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"
      LINE 1: CREATE TABLE User (id INT NOT NULL, username VARCHAR(50) NOT...
      ^' 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).

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Doctrine does not do auto-escaping.

        Please read the docs on quoting reserved words: http://www.doctrine-project.org/docs/orm/2.0/en/reference/basic-mapping.html#quoting-reserved-words

        Show
        Benjamin Eberlei added a comment - Doctrine does not do auto-escaping. Please read the docs on quoting reserved words: http://www.doctrine-project.org/docs/orm/2.0/en/reference/basic-mapping.html#quoting-reserved-words
        Hide
        Timo A. Hummel added a comment -

        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:

        DROP TABLE User

        That fails, of course.

        Show
        Timo A. Hummel added a comment - 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: DROP TABLE User That fails, of course.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Timo A. Hummel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: