Domanda

Some of my columns got truncated. After some research I managed to create this Minimal Working Example, that works on MySQL 5.0.96-community:

DROP TABLE IF EXISTS test;
CREATE TABLE test (
  a char(3),  
  b char(3),  
  c smallint
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO test VALUES(
  "אאא",
  "בבב",
  111);

SELECT CONCAT(a,b,c) FROM test;  
   // RESULT: "אאאבבב111"

DROP TABLE IF EXISTS test2;
CREATE TABLE test2 SELECT CONCAT(a,b,c) AS d FROM test;

SELECT d FROM test2;
   // RESULT: "אאאבבב"

Is this a bug or a feature?

È stato utile?

Soluzione

CAST int to char. I hope, it will work.

CREATE TABLE test2 SELECT CONCAT(a,b,CAST(c AS CHAR)) AS d FROM test;

Update:

After Lightness Races in Orbit's comment, I tried it for myself. Usually, it works just fine. But since your version is a bit older one, it is not working.

You can use it like the following way:

CREATE TABLE test2 (d char(9));

INSERT INTO test2
    SELECT CONCAT(a,b,c) AS d FROM test;

See the sqlfiddle: http://sqlfiddle.com/#!8/d9433/1

Altri suggerimenti

You didn't specify that the new table should be UTF-8.

CREATE TABLE test2 CHARSET=utf8 SELECT CONCAT(a,b,c) AS d FROM test;
--                 ^^^^^^^^^^^^^
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top