Don't include sizes on primitive datatypes that shouldn't have them when modifying columns. Fixes #3052

pull/7/head
Harshal Dhumal 2018-02-01 16:00:32 +01:00 committed by Dave Page
parent 6ad44cb51e
commit 2042f89ce0
4 changed files with 47 additions and 17 deletions

View File

@ -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']
)

View File

@ -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 %}

View File

@ -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 = ' '

View File

@ -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