Hi,.

Issue was caused due to we were considering internal datatype length (eg.
smallint 2 bytes, int4 4 bytes, integer 8 bytes) as user configurable
length.
However we cannot change internal datatype lengths of some primitive
datatypes.

-- 
*Harshal Dhumal*
*Sr. Software Engineer*

EnterpriseDB India: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
index f152392..f911bbb 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
@@ -1690,10 +1690,8 @@ class BaseTableView(PGChildNodeView):
                             old_data['isdup'], old_data['attndims'], old_data['atttypmod']
                         )
 
-                        length = False
-                        precision = False
-
-                        # If the column data type has not changed then fetch old length and precision
+                        # If the column data type has not changed then fetch
+                        # old length and precision
                         if 'elemoid' in old_data and 'cltype' not in c:
                             length, precision, typeval = \
                                 self.get_length_precision(old_data['elemoid'])
@@ -1714,6 +1712,23 @@ class BaseTableView(PGChildNodeView):
                                 c['attlen'] = None
                                 c['attprecision'] = None
 
+                        if 'cltype' in c:
+                            typename = c['cltype']
+                            if 'hasSqrBracket' in c and c['hasSqrBracket']:
+                                typename += '[]'
+                            length, precision, typeval = \
+                                self.get_length_precision(typename)
+
+                            # if new datatype does not have length or precision
+                            # then we cannot apply length or precision of old
+                            # datatype to new one.
+
+                            if not length:
+                                old_data['attlen'] = -1
+
+                            if not precision:
+                                old_data['attprecision'] = None
+
                         old_data['cltype'] = DataTypeReader.parse_type_name(
                             old_data['cltype']
                         )
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/macros/get_full_type_sql_format.macros b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/macros/get_full_type_sql_format.macros
index 9e7276f..1520232 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/macros/get_full_type_sql_format.macros
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/macros/get_full_type_sql_format.macros
@@ -59,5 +59,5 @@ time({{ data.attlen }}) with time zone {% endif %}{% if o_data.hasSqrBracket %}[
 ({{ data.attlen }}{% elif o_data.attlen and o_data.attlen != 'None' %}({{ o_data.attlen }}{% endif %}{% if data.attprecision and data.attprecision != 'None' %}
 , {{ data.attprecision }}){% elif o_data.attprecision and o_data.attprecision != 'None' %}, {{ o_data.attprecision }}){% else %}){% endif %}
 {% endif %}
-{% endif %}
+{% endif %}{% if o_data.hasSqrBracket %}[]{% endif %}
 {% endmacro %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
index bba36ed..ddebd5e 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
@@ -15,6 +15,7 @@ from flask import render_template
 from pgadmin.browser.collection import CollectionNodeModule
 from pgadmin.utils.ajax import internal_server_error
 
+
 class SchemaChildModule(CollectionNodeModule):
     """
     Base class for the schema child node.
@@ -149,20 +150,35 @@ class DataTypeReader:
         return True, res
 
     @staticmethod
-    def get_length_precision(elemoid):
+    def get_length_precision(elemoid_or_name):
         precision = False
         length = False
         typeval = ''
 
-        # Check against PGOID for specific type
-        if elemoid:
-            if elemoid in (1560, 1561, 1562, 1563, 1042, 1043,
-                                  1014, 1015):
+        # Check against PGOID/typename for specific type
+        if elemoid_or_name:
+            if elemoid_or_name in (1560, 'bit',
+                                   1561, 'bit[]',
+                                   1562, 'varbit', 'bit varying',
+                                   1563, 'varbit[]', 'bit varying[]',
+                                   1042, 'bpchar', 'character',
+                                   1043, 'varchar', 'character varying',
+                                   1014, 'bpchar[]', 'character[]',
+                                   1015, 'varchar[]', 'character varying[]'):
                 typeval = 'L'
-            elif elemoid in (1083, 1114, 1115, 1183, 1184, 1185,
-                                    1186, 1187, 1266, 1270):
+            elif elemoid_or_name in (1083, 'time', 'time without time zone',
+                                     1114, 'timestamp', 'timestamp without time zone',
+                                     1115, 'timestamp[]', 'timestamp without time zone[]',
+                                     1183, 'time[]', 'time without time zone[]',
+                                     1184, 'timestamptz', 'timestamp with time zone',
+                                     1185, 'timestamptz[]', 'timestamp with time zone[]',
+                                     1186, 'interval',
+                                     1187, 'interval[]', 'interval[]',
+                                     1266, 'timetz', 'time with time zone',
+                                     1270, 'timetz', 'time with time zone[]'):
                 typeval = 'D'
-            elif elemoid in (1231, 1700):
+            elif elemoid_or_name in (1231, 'numeric[]',
+                                     1700, 'numeric'):
                 typeval = 'P'
             else:
                 typeval = ' '
diff --git a/web/pgadmin/utils/driver/psycopg2/typecast.py b/web/pgadmin/utils/driver/psycopg2/typecast.py
index bd47216..f136604 100644
--- a/web/pgadmin/utils/driver/psycopg2/typecast.py
+++ b/web/pgadmin/utils/driver/psycopg2/typecast.py
@@ -82,10 +82,9 @@ RECORD_ARRAY = (2287,)
 
 PSYCOPG_SUPPORTED_BUILTIN_ARRAY_DATATYPES = (
     1016, 1005, 1006, 1007, 1021, 1022, 1231,
-    1002, 1003, 1009, 1014, 1015, 1002, 1003,
-    1009, 1014, 1015, 1000, 1115, 1185, 1183,
-    1270, 1182, 1187, 1001, 1028, 1013, 1041,
-    651, 1040
+    1002, 1003, 1009, 1014, 1015, 1009, 1014,
+    1015, 1000, 1115, 1185, 1183, 1270, 1182,
+    1187, 1001, 1028, 1013, 1041, 651, 1040
 )
 
 # json, jsonb

Reply via email to