Doctrine 1
  1. Doctrine 1
  2. DC-996

UPDATE query generate ambiguous statement

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Query
    • Labels:
      None
    • Environment:
      MAMP on MacBook Pro 10.6.7, with Symfony 1.4.9

      Description

      When creating an UPDATE query, the table names are not aliased like in a SELECT statement. This causes ambiguous column names when JOINING in an UPDATE.

      E.g.
      $q = $this->createQuery('st')
      ->update('SomeTable st')
      ->set('st.position','st.position + 1')
      ->leftJoin('st.SomeOtherTable sot ON st.some_id = sot.id')
      ->where('st.id <> ?', $someId)
      ->andWhere('sot.some_column = ?', $someValue)

      The generated SQL for this is :
      UPDATE some_table
      LEFT JOIN some_other_table sot ON st.some_id = sot.id
      SET position = position + 1, updated_at = 2011-04-13 11:01:03, updated_at = 2011-04-13 11:01:03
      WHERE (id <> 4 AND some_column = 7)

      Clearly here "updated_at" and "id" are ambiguous columns. Why the tables are not automatically aliased with unique aliases like in a SELECT statement, and the aliases written before the column name ?

      Thanks.

        Activity

        John created issue -
        John made changes -
        Field Original Value New Value
        Description When creating an UPDATE query, the table names are not aliased like in a SELECT statement. This causes ambiguous column names when JOINING in an UPDATE.

        E.g.
        $q = $this->createQuery('st')
        ->update('SomeTable st')
        ->set('st.position','st.position + 1')
        ->leftJoin('st.SomeOtherTable sot ON st.some_id = sot.id')
        ->where('st.id <> ?', $someId)

        The generated SQL for this is :
        UPDATE some_table
        LEFT JOIN some_other_table sot ON st.some_id = sot.id
        SET position = position + 1, updated_at = 2011-04-13 11:01:03, updated_at = 2011-04-13 11:01:03
        WHERE id <> 4

        Clearly here "updated_at" and "id" are ambiguous columns. Why the tables are not automatically aliased with unique aliases like in a SELECT statement, and the aliases written before the column name ?

        Thanks.
        When creating an UPDATE query, the table names are not aliased like in a SELECT statement. This causes ambiguous column names when JOINING in an UPDATE.

        E.g.
        $q = $this->createQuery('st')
        ->update('SomeTable st')
        ->set('st.position','st.position + 1')
        ->leftJoin('st.SomeOtherTable sot ON st.some_id = sot.id')
        ->where('st.id <> ?', $someId)
        ->andWhere('sot.some_column = ?', $someValue)

        The generated SQL for this is :
        UPDATE some_table
        LEFT JOIN some_other_table sot ON st.some_id = sot.id
        SET position = position + 1, updated_at = 2011-04-13 11:01:03, updated_at = 2011-04-13 11:01:03
        WHERE (id <> 4 AND some_column = 7)

        Clearly here "updated_at" and "id" are ambiguous columns. Why the tables are not automatically aliased with unique aliases like in a SELECT statement, and the aliases written before the column name ?

        Thanks.

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-996, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            John
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: