mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix SQL issue of length and precision when changing the data type of Column. Fixes #4698
This commit is contained in:
@@ -524,10 +524,20 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
Returns:
|
||||
Converted data
|
||||
"""
|
||||
if 'attlen' in data and data['attlen'] is not None:
|
||||
|
||||
# We need to handle the below case because jquery has changed
|
||||
# undefined/null values to empty strings
|
||||
# https://github.com/jquery/jquery/commit/36d2d9ae937f626d98319ed850905e8d1cbfd078
|
||||
if 'attlen' in data and data['attlen'] == '':
|
||||
data['attlen'] = None
|
||||
elif 'attlen' in data and data['attlen'] is not None:
|
||||
data['attlen'] = str(data['attlen'])
|
||||
if 'attprecision' in data and data['attprecision'] is not None:
|
||||
|
||||
if 'attprecision' in data and data['attprecision'] == '':
|
||||
data['attprecision'] = None
|
||||
elif 'attprecision' in data and data['attprecision'] is not None:
|
||||
data['attprecision'] = str(data['attprecision'])
|
||||
|
||||
return data
|
||||
|
||||
@check_precondition
|
||||
@@ -791,6 +801,18 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
|
||||
old_data['cltype'] = self._cltype_formatter(old_data['cltype'])
|
||||
old_data['hasSqrBracket'] = self.hasSqrBracket
|
||||
|
||||
if 'cltype' in data and data['cltype'] != old_data['cltype']:
|
||||
length, precision, typeval = \
|
||||
self.get_length_precision(data['cltype'])
|
||||
|
||||
# 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
|
||||
|
||||
# If name is not present in data then
|
||||
# we will fetch it from old data, we also need schema & table name
|
||||
if 'name' not in data:
|
||||
|
||||
Reference in New Issue
Block a user