Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-68799

DDL API returns an invalid ALTER statement for a field with a sequence in Postgres

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.8.3
    • Fix Version/s: None
    • Component/s: Database SQL/XMLDB
    • Labels:
      None
    • Affected Branches:
      MOODLE_38_STABLE

      Description

      If you try to alter a field that has a sequence modifier (e.g. a primary key) using the 'change_field_type' API function, it will fail using Postgres. This is due to an invalid ALTER SQL statement being returned.

      For example, if you try to modify the length (precision) to '10' of a field named 'id' that also has 'sequence' set to XMLDB_SEQUENCE, the SQL that gets returned for Postgres looks like:

      "ALTER TABLE mdl_mytable ALTER COLUMN id TYPEid BIGSERIAL"

      It should be returning something like:

      "ALTER TABLE mdl_mytable ALTER COLUMN id TYPE BIGINT"

      This seems to be caused by the code in lines 512 through 525 of "lib/ddl/sql_generator.php::getFieldSQL()".

      Essentially, it modifies the return value to contain "id BIGSERIAL" instead of "BIGINT".

      This only seems to happen using Postgres, so it is likely the code that calls this at line 339 of "lib/ddl/postgres_sql_generator.php::getAlterFieldSQL()" is using the returned value of "getFieldSQL()" incorrectly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              mchurch Mike Churchward
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated: