diff -u b/src/Storage/IntColumnHandlerPostgreSQL.php b/src/Storage/IntColumnHandlerPostgreSQL.php --- b/src/Storage/IntColumnHandlerPostgreSQL.php +++ b/src/Storage/IntColumnHandlerPostgreSQL.php @@ -49,7 +49,7 @@ $function_name = $this->getFunctionName($table, $column_int); // It is much easier to just drop and recreate than figuring it out whether // it exists. - $this->connection->query("DROP FUNCTION IF EXISTS $function_name"); + $this->connection->query("DROP FUNCTION IF EXISTS $function_name()"); $query = "CREATE FUNCTION $function_name() RETURNS trigger AS $$ BEGIN NEW.$column_int = (CASE WHEN NEW.$column ~ '^[0-9]+$' THEN NEW.$column ELSE '0' END)::integer"; @@ -61,13 +61,14 @@ protected function createTrigger($table, $column, $column_int) { $function_name = $this->getFunctionName($table, $column_int); + $prefixed_table = $this->getPrefixedTable($table); // It is much easier to just drop and recreate than figuring it out whether // it exists. - $this->connection->query("DROP TRIGGER IF EXISTS $function_name"); + $this->connection->query("DROP TRIGGER IF EXISTS $column_int ON $prefixed_table"); $this->connection->query(" - CREATE TRIGGER $function_name + CREATE TRIGGER $column_int BEFORE INSERT OR UPDATE - ON {" . "$table} + ON $prefixed_table FOR EACH ROW EXECUTE PROCEDURE $function_name(); "); @@ -79,7 +80,15 @@ * @return string */ protected function getFunctionName($table, $column_int) { - return implode('_', [$this->connection->prefixTables('{' . $table . '}'), $column_int]); + return implode('_', [$this->getPrefixedTable($table), $column_int]); + } + + /** + * @param $table + * @return string + */ + protected function getPrefixedTable($table) { + return $this->connection->prefixTables('{' . $table . '}'); } }