Mega Code Archive

 
Categories / MySQL / String
 

Preserving Trailing Spaces in String Columns

mysql> mysql> CREATE TABLE t (c VARCHAR(255)); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO t (c) VALUES('abc '); Query OK, 1 row affected (0.00 sec) mysql> SELECT c, LENGTH(c) FROM t; +------+-----------+ | c    | LENGTH(c) | +------+-----------+ | abc  |         4 | +------+-----------+ 1 row in set (0.00 sec) mysql> mysql> mysql> DROP TABLE t; Query OK, 0 rows affected (0.00 sec) mysql> mysql> mysql> CREATE TABLE t (c TEXT); Query OK, 0 rows affected (0.01 sec) mysql> INSERT INTO t (c) VALUES('abc '); Query OK, 1 row affected (0.00 sec) mysql> SELECT c, LENGTH(c) FROM t; +------+-----------+ | c    | LENGTH(c) | +------+-----------+ | abc  |         4 | +------+-----------+ 1 row in set (0.00 sec) mysql> mysql> drop table t; Query OK, 0 rows affected (0.00 sec)