diff --git a/packages/nc-gui/components/cell/MultiSelect.vue b/packages/nc-gui/components/cell/MultiSelect.vue index 4ddf85d24d..1b59039051 100644 --- a/packages/nc-gui/components/cell/MultiSelect.vue +++ b/packages/nc-gui/components/cell/MultiSelect.vue @@ -209,17 +209,19 @@ async function addIfMissingAndSave() { const updatedColMeta = { ...column.value } // todo: refactor and avoid repetition - // Postgres returns default value wrapped with single quotes & casted with type so we have to get value between single quotes to keep it unified for all databases - if (isPg.value) { - updatedColMeta.cdf = updatedColMeta.cdf.substring( - updatedColMeta.cdf.indexOf(`'`) + 1, - updatedColMeta.cdf.lastIndexOf(`'`), - ) - } - - // Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped - if (!isMysql.value) { - updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'") + if (updatedColMeta.cdf) { + // Postgres returns default value wrapped with single quotes & casted with type so we have to get value between single quotes to keep it unified for all databases + if (isPg.value) { + updatedColMeta.cdf = updatedColMeta.cdf.substring( + updatedColMeta.cdf.indexOf(`'`) + 1, + updatedColMeta.cdf.lastIndexOf(`'`), + ) + } + + // Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped + if (!isMysql.value) { + updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'") + } } await $api.dbTableColumn.update( diff --git a/packages/nc-gui/components/cell/SingleSelect.vue b/packages/nc-gui/components/cell/SingleSelect.vue index e75739aeb7..b89bad6bc2 100644 --- a/packages/nc-gui/components/cell/SingleSelect.vue +++ b/packages/nc-gui/components/cell/SingleSelect.vue @@ -132,17 +132,19 @@ async function addIfMissingAndSave() { const updatedColMeta = { ...column.value } // todo: refactor and avoid repetition - // Postgres returns default value wrapped with single quotes & casted with type so we have to get value between single quotes to keep it unified for all databases - if (isPg.value) { - updatedColMeta.cdf = updatedColMeta.cdf.substring( - updatedColMeta.cdf.indexOf(`'`) + 1, - updatedColMeta.cdf.lastIndexOf(`'`), - ) - } - - // Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped - if (!isMysql.value) { - updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'") + if (updatedColMeta.cdf) { + // Postgres returns default value wrapped with single quotes & casted with type so we have to get value between single quotes to keep it unified for all databases + if (isPg.value) { + updatedColMeta.cdf = updatedColMeta.cdf.substring( + updatedColMeta.cdf.indexOf(`'`) + 1, + updatedColMeta.cdf.lastIndexOf(`'`), + ) + } + + // Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped + if (!isMysql.value) { + updatedColMeta.cdf = updatedColMeta.cdf.replace(/''/g, "'") + } } await $api.dbTableColumn.update(