mysql - SQL query with ALTER TABLE print error #1064 in query execution
问题描述
I've built an SQL query in Aruba MySQL database using the alter table Statement to generate a new column with comma-separated values. I'm trying to automate the concatenate function every time a new record is submitted into the database table. After I execute the query I always get a #1064 error.
ALTER TABLE 1459630_form_1
ADD COLUMN 'datimarketing'
MEDIUMTEXT GENERATED ALWAYS AS (CONCAT(`segmento_auto_richiesto`,',',`alimentazione`,',',`km_annui_percorsi`,',',`modalit_di_acquisto`,',',`budget_di_spesa`,',',`rata_mensile`,',',`abitudini_di_acquisto`,',',`numero_di_componenti_del_nucleo_familiare`,',',`hobby`,',',`professione`,',',`iscritto_ad_associazioni_di_categoria`,',',`privacy_mkt_all`,',',`giorno_preferito_per_il_ricontatto`,',',`orario_preferito_per_il_ricontatto`)) STORED AFTER `orario_preferito_per_il_ricontatto`
UPDATE TABLE(1459630_form_1)
Somebody could help me? Thanks
解决方案
In MySQL the syntax goes like:
ALTER TABLE 1459630_form_1
ADD COLUMN datimarketing MEDIUMTEXT
GENERATED ALWAYS AS (CONCAT_WS(',', `segmento_auto_richiesto`, `alimentazione`, `km_annui_percorsi`)) STORED
AFTER `orario_preferito_per_il_ricontatto`
;
I shorten the number of concatenated columns to make the code more readable (but the logic is the same of course).
Rationale:
the column name should not be surrounded with single quotes
parentheses need to balance
UPDATE TABLE()
is not applicable here
Side note: CONCAT_WS()
comes handy to shorten the CONCAT()
expression.
推荐阅读
- java - springboot 启动失败,Linux 服务器安装了 dynatrace 代理(APM)
- magento - Magento 2.3.4 版本。如何更改产品明智的标题标签标题?
- java - 双重身份验证机制:SSO 和 DB 凭据
- mocha.js - 测试重试时 Mochawesome 报告中的屏幕截图失败
- c# - 使用 c# 从 S3 存储桶下载对象总是超时
- javascript - 如何使用 React Keycloak?
- jquery - [Vue 警告]:挂载钩子中的错误:“TypeError:element.circleProgress 不是函数”
- mysql - 在MySQL中特定时间后删除表中的记录
- flutter - 如何在容器中心垂直和水平地画一条线?
- bash - 如何通过 bash 脚本使用此处的字符串将字母传递给 abaqus 数据检查?