From 84eea02ac52042bfbee3bd2ed8d24993c7c594e6 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 16 Feb 2015 12:00:40 +0100 Subject: [PATCH] [IMP] models.py: try in place column cast before copy --- openerp/models.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/openerp/models.py b/openerp/models.py index 29a229f668c..6fc74cea170 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -2522,10 +2522,15 @@ class BaseModel(object): if (f_pg_type==c[0]) and (f._type==c[1]): if f_pg_type != f_obj_type: ok = True - cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO __temp_type_cast' % (self._table, k)) - cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, c[2])) - cr.execute(('UPDATE "%s" SET "%s"= __temp_type_cast'+c[3]) % (self._table, k)) - cr.execute('ALTER TABLE "%s" DROP COLUMN __temp_type_cast CASCADE' % (self._table,)) + try: + with cr.savepoint(): + cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" TYPE %s' % (self._table, k, c[2]), log_exceptions=False) + except psycopg2.NotSupportedError: + # can't do inplace change -> use a casted temp column + cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO __temp_type_cast' % (self._table, k)) + cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' % (self._table, k, c[2])) + cr.execute('UPDATE "%s" SET "%s"= __temp_type_cast%s' % (self._table, k, c[3])) + cr.execute('ALTER TABLE "%s" DROP COLUMN __temp_type_cast CASCADE' % (self._table,)) cr.commit() _schema.debug("Table '%s': column '%s' changed type from %s to %s", self._table, k, c[0], c[1])