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

    • Icon: Bug Bug
    • Resolution: Deferred
    • Icon: Minor Minor
    • None
    • 3.8.3
    • Database SQL/XMLDB
    • None
    • MOODLE_38_STABLE

      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.

            Unassigned Unassigned
            mchurch Mike Churchward
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.