1

In Magento 2's migration/data-definition-language, there are two column type constants

#File: vendor/magento/framework/DB/Ddl/Table.php
const TYPE_NUMERIC = 'numeric';
const TYPE_DECIMAL = 'decimal';

Is there any difference in table columns created with these constants? It doesn't look like the TYPE_NUMERIC constant is used anywhere, so its unclear if its just legacy cruft, or somehow subtly different from TYPE_DECIMAL

3

According to framework/DB/Adapter/Pdo/Mysql.php, they're the synonyms, meaning they're the same column type:

protected $_ddlColumnTypes      = [
    Table::TYPE_BOOLEAN       => 'bool',
    Table::TYPE_SMALLINT      => 'smallint',
    Table::TYPE_INTEGER       => 'int',
    Table::TYPE_BIGINT        => 'bigint',
    Table::TYPE_FLOAT         => 'float',
    Table::TYPE_DECIMAL       => 'decimal',
    Table::TYPE_NUMERIC       => 'decimal',
    Table::TYPE_DATE          => 'date',
    Table::TYPE_TIMESTAMP     => 'timestamp',
    Table::TYPE_DATETIME      => 'datetime',
    Table::TYPE_TEXT          => 'text',
    Table::TYPE_BLOB          => 'blob',
    Table::TYPE_VARBINARY     => 'blob',
];

This is confirmed by the _getColumnDefinition method:

        case Table::TYPE_DECIMAL:
        case Table::TYPE_NUMERIC:
            $precision  = 10;
            $scale      = 0;
            $match      = [];
            if (!empty($options['LENGTH']) && preg_match('#^\(?(\d+),(\d+)\)?$#', $options['LENGTH'], $match)) {
                $precision  = $match[1];
                $scale      = $match[2];
            } else {
                if (isset($options['SCALE']) && is_numeric($options['SCALE'])) {
                    $scale = $options['SCALE'];
                }
                if (isset($options['PRECISION']) && is_numeric($options['PRECISION'])) {
                    $precision = $options['PRECISION'];
                }
            }
            $cType .= sprintf('(%d,%d)', $precision, $scale);
            break;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.