Commit 0aec71aa authored by Dries's avatar Dries

- Patch #256001 by bjaspan: pgsql driver does not handle unsigned numeric fields.

parent f28c0ae5
......@@ -597,12 +597,30 @@ function _db_create_field_sql($name, $spec) {
if ($spec['type'] == 'serial') {
unset($spec['not null']);
}
// pgsql does not have unsigned types but supports constraints to
// restricted a signed field to be non-negative (e.g. CHECK (VALUE
// >= 0)). system.module defines {,small,big}int_unsigned as the
// corresponding integer type with this constraint but does not do
// so for serial or numeric types. It probably would have been
// cleaner to unify unsigned handling but, for now, we use the
// *int_unsigned types for int and otherwise apply a column
// constraint explicitly.
if (!empty($spec['unsigned'])) {
if ($spec['type'] == 'serial') {
$sql .= " CHECK ($name >= 0)";
}
else {
$sql .= '_unsigned';
switch ($spec['type']) {
case 'int':
$sql .= '_unsigned';
break;
case 'serial':
case 'float':
$sql .= " CHECK ($name >= 0)";
break;
case 'numeric':
// handled below
break;
default:
// unsigned is not supported on other column types
break;
}
}
......@@ -613,6 +631,11 @@ function _db_create_field_sql($name, $spec) {
$sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
}
// For numeric columns this has to come after (precision,scale).
if ($spec['type'] == 'numeric' && !empty($spec['unsigned'])) {
$sql .= " CHECK ($name >= 0)";
}
if (isset($spec['not null']) && $spec['not null']) {
$sql .= ' NOT NULL';
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment