/** * Gets the PostgreSQL Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column) { $buffer = array(); if ($column->isIdentity()) { $buffer[] = 'SERIAL'; } else { $sqlType = $this->getSqlType($column->getType(), $column->getLimit()); $buffer[] = strtoupper($sqlType['name']); // integers cant have limits in postgres if (static::PHINX_TYPE_DECIMAL === $sqlType['name'] && ($column->getPrecision() || $column->getScale())) { $buffer[] = sprintf('(%s, %s)', $column->getPrecision() ? $column->getPrecision() : $sqlType['precision'], $column->getScale() ? $column->getScale() : $sqlType['scale']); } elseif (!in_array($sqlType['name'], array('integer', 'smallint'))) { if ($column->getLimit() || isset($sqlType['limit'])) { $buffer[] = sprintf('(%s)', $column->getLimit() ? $column->getLimit() : $sqlType['limit']); } } $timeTypes = array('time', 'timestamp'); if (in_array($sqlType['name'], $timeTypes) && $column->isTimezone()) { $buffer[] = strtoupper('with time zone'); } } $buffer[] = $column->isNull() ? 'NULL' : 'NOT NULL'; if (!is_null($column->getDefault())) { $buffer[] = $this->getDefaultValueDefinition($column->getDefault()); } return implode(' ', $buffer); }
/** * Gets the PostgreSQL Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column) { $buffer = array(); if ($column->isIdentity()) { $buffer[] = 'SERIAL'; } else { $sqlType = $this->getSqlType($column->getType()); $buffer[] = strtoupper($sqlType['name']); // integers cant have limits in postgres if ('integer' !== $sqlType['name'] && ($column->getLimit() || isset($sqlType['limit']))) { $buffer[] = sprintf('(%s)', $column->getLimit() ? $column->getLimit() : $sqlType['limit']); } $timeTypes = array('time', 'timestamp'); if (in_array($sqlType['name'], $timeTypes) && $column->isTimezone()) { $buffer[] = strtoupper('with time zone'); } } $buffer[] = $column->isNull() ? 'NULL' : 'NOT NULL'; if (!is_null($column->getDefault())) { $buffer[] = $this->getDefaultValueDefinition($column->getDefault()); } // TODO - add precision & scale for decimals return implode(' ', $buffer); }