I've used Trim()
method to remove spaces from data before insert in DB. I'm using Nodejs and Sequelize. But is there something that is used to do that and for example if I have array, to pass this array, not to loop through all elements to strip spaces? Thanks.
Create a mysql trigger that will trim your field on insert
Create them for each of the fields you want trimmed.
I verified this is working on mysql workbench.
Create a mysql trigger that will trim your field on insert
Create them for each of the fields you want trimmed. Example:
I verified this is working on mysql workbench.
Source : Automatically trimming CHAR data on insert into VARCHAR column
Code:
DROP TABLE IF EXISTS tmp; CREATE TABLE tmp ('txt' varchar(50)); DROP TRIGGER IF EXISTS insert_tmp; CREATE TRIGGER insert_tmp BEFORE INSERT ON tmp FOR EACH ROW SET NEW.txt=TRIM(NEW.txt); INSERT INTO tmp VALUES (" abc "), ("efg "); SELECT txt, LENGTH(txt) FROM tmp;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments