Hello all,

 

I'm trying to get a TEXT field updated with its own content and an extra
string by using concat. The query looks something like this:

 

update field_comment set field_comment = concat(field_comment, '\n
my_new_string');

 

I've noticed that in this case the update doesn't work when the content of
the field is empty.  I tried setting up a testcase, and as long as the
textfield is NULL concat doesn't return anything. Is this 'as designed' or a
bug? Should it work as designed, would anyone know another easy way without
setting a byte first?

 

Below the testcase:

 

CREATE TABLE memo_test (id INT (1) UNSIGNED DEFAULT '0' NOT NULL, comments
TEXT, PRIMARY KEY(id))  TYPE = MyISAM;

INSERT INTO memo_test (id, comments) VALUES (1, NULL);

INSERT INTO memo_test (id, comments) VALUES (2, 'Hello');

 

select concat(comments, 'Does not work') from memo_test

 

+-----------------------------------+

| concat(comments, 'Does not work') |

+-----------------------------------+

| NULL                              |

| HelloDoes not work                |

+-----------------------------------+

 

select concat('Something', comments, 'Does not work') from memo_test;

+------------------------------------------------+

| concat('Something', comments, 'Does not work') |

+------------------------------------------------+

| NULL                                           |

| SomethingHelloDoes not work                    |

+------------------------------------------------+

 

Best regards,

 

Almar van Pel

www.makeweb.nl     

 

Reply via email to