mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-24 15:26:46 -06:00
Ensure that default values are set only for insert statement if user does not provide any values, in case of updating existing values to blank it should be set to null. #5934
Incorporated review comments
This commit is contained in:
parent
49b5ab71c2
commit
eef7461ae6
@ -1293,11 +1293,6 @@ export function ResultSet() {
|
||||
let row = newRows[otherInfo.indexes[0]];
|
||||
let clientPK = rowKeyGetter(row);
|
||||
|
||||
// Check if column is pk and value is null set it to default value.
|
||||
if(otherInfo.column.has_default_val && _.isNull(row[otherInfo.column.key])) {
|
||||
row[otherInfo.column.key] = undefined;
|
||||
}
|
||||
|
||||
if(clientPK in (dataChangeStore.added || {})) {
|
||||
/* No need to track this */
|
||||
} else if(clientPK in (dataChangeStore.updated || {})) {
|
||||
|
@ -4,7 +4,7 @@ INSERT INTO {{ conn|qtIdent(nsp_name, object_name) | replace("%", "%%") }} (
|
||||
{% if not loop.first %}, {% endif %}{{ conn|qtIdent(col) | replace("%", "%%") }}{% endfor %}
|
||||
) VALUES (
|
||||
{% for col in data_to_be_saved %}
|
||||
{% if not loop.first %}, {% endif %}%({{ pgadmin_alias[col] }})s{% if type_cast_required[col] %}::{{ data_type[col] }}{% endif %}{% endfor %}
|
||||
{% if not loop.first %}, {% endif %}{% if data_to_be_saved[col] == 'set_default' and use_default %} DEFAULT {% else %}%({{ pgadmin_alias[col] }})s{% if type_cast_required[col] %}::{{ data_type[col] }}{% endif %}{% endif %}{% endfor %}
|
||||
)
|
||||
{% if pk_names and not has_oids %} returning {{pk_names | replace("%", "%%")}}{% endif %}
|
||||
{% if has_oids %} returning oid{% endif %};
|
||||
|
@ -120,6 +120,12 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
|
||||
# Update columns value with columns having
|
||||
# not_null=False and has no default value
|
||||
column_data.update(data)
|
||||
use_default = False
|
||||
if not column_data:
|
||||
for each_col in columns_info:
|
||||
if columns_info[each_col]['has_default_val']:
|
||||
column_data[each_col] = 'set_default'
|
||||
use_default = True
|
||||
|
||||
sql = render_template(
|
||||
"/".join([command_obj.sql_path, 'insert.sql']),
|
||||
@ -131,7 +137,8 @@ def save_changed_data(changed_data, columns_info, conn, command_obj,
|
||||
data_type=column_type,
|
||||
pk_names=pk_names,
|
||||
has_oids=command_obj.has_oids(),
|
||||
type_cast_required=type_cast_required
|
||||
type_cast_required=type_cast_required,
|
||||
use_default=use_default
|
||||
)
|
||||
|
||||
select_sql = render_template(
|
||||
|
Loading…
Reference in New Issue
Block a user