diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index e369d39b4e4..505288653c2 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -478,7 +478,14 @@ class pgsql_native_moodle_database extends moodle_database { $info->scale = null; $info->not_null = ($rawcolumn->attnotnull === 't'); if ($info->has_default) { - $info->default_value = trim($rawcolumn->adsrc, '()'); + // PG 9.5+ uses :: syntax for some defaults. + $parts = explode('::', $rawcolumn->adsrc); + if (count($parts) > 1) { + $info->default_value = reset($parts); + } else { + $info->default_value = $rawcolumn->adsrc; + } + $info->default_value = trim($info->default_value, "()'"); } else { $info->default_value = null; } @@ -496,7 +503,14 @@ class pgsql_native_moodle_database extends moodle_database { $info->not_null = ($rawcolumn->attnotnull === 't'); $info->has_default = ($rawcolumn->atthasdef === 't'); if ($info->has_default) { - $info->default_value = trim($rawcolumn->adsrc, '()'); + // PG 9.5+ uses :: syntax for some defaults. + $parts = explode('::', $rawcolumn->adsrc); + if (count($parts) > 1) { + $info->default_value = reset($parts); + } else { + $info->default_value = $rawcolumn->adsrc; + } + $info->default_value = trim($info->default_value, "()'"); } else { $info->default_value = null; } @@ -514,7 +528,14 @@ class pgsql_native_moodle_database extends moodle_database { $info->not_null = ($rawcolumn->attnotnull === 't'); $info->has_default = ($rawcolumn->atthasdef === 't'); if ($info->has_default) { - $info->default_value = trim($rawcolumn->adsrc, '()'); + // PG 9.5+ uses :: syntax for some defaults. + $parts = explode('::', $rawcolumn->adsrc); + if (count($parts) > 1) { + $info->default_value = reset($parts); + } else { + $info->default_value = $rawcolumn->adsrc; + } + $info->default_value = trim($info->default_value, "()'"); } else { $info->default_value = null; }