2013-05-17 68 views
0

这是我的数据库架构:为什么我得到这个奇怪的结果:[BLOB - ...]?

Post: 
id 
title 
body 
date 

Tag: 
id 
title 

Post_Tag: 
id 
id_post 
id_tag 

Comment: 
id 
id_post 
body 
date 

,这是我的查询:

SELECT 
    Post.id AS post_id, 
    Post.title AS post_title, 
    Post.body AS post_body, 
    GROUP_CONCAT(CONCAT(Tag.id, "|", Tag.title) SEPARATOR '#') AS tags, 
    COUNT(Comment.id) AS comment_count 
FROM Post 
LEFT JOIN Comment ON Post.id = Comment.id_post 
LEFT JOIN Post_Tag ON Post.id = Post_Tag.id_post 
LEFT JOIN Tag ON Tag.id = Post_Tag.id_tag 
GROUP BY Post.id 
ORDER BY Post.date ASC 

有人能告诉我为什么我收到这些奇怪的结果([BLOB - ...])以下标签列?

id title   body   tags   comment_count 
1 hello guys blablabla... [BLOB - 8B]   8 
2 hello all blablabla... [BLOB - 14B]  3 
3 how to tell blablabla... [BLOB - 8B]   5 
4 hello world blablabla... [BLOB - 5B]   7 
+0

http://dev.mysql.com/doc/refman/5.0/en/blob.html – RRikesh

+0

确定,但我怎么能得到正确的结果:)? – user2393238

回答

0

替换:

GROUP_CONCAT(CONCAT(Tag.id, "|", Tag.title) SEPARATOR '#') AS tags, 

有了:

CAST(GROUP_CONCAT(CONCAT(Tag.id, "|", Tag.title) SEPARATOR '#') AS CHAR) AS tags, 

文档:CAST function

1

这是一个比较知名的配置问题:您group_concat_max_len设置为一个较大的值,迫使MySql使用BLOB而不是varchar秒的结果为group_concat

要修复,请在my.inimy.cnf文件中将group_concat_max_len设置为512,然后重新启动MySql。

这是link to a post with more information

0

您也可以使用CONVERT()和BLOB数据转换为utf8

CONVERT(GROUP_CONCAT(CONCAT(Tag.id, "|", Tag.title) SEPARATOR '#') AS tags USING utf8), 
相关问题