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

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.8.3
    • None
    • Database SQL/XMLDB
    • None
    • 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

              Unassigned Unassigned
              mchurch Mike Churchward
              David Woloszyn, Huong Nguyen, Jake Dallimore, Michael Hawkins, Stevani Andolo
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: