tags:

views:

1086

answers:

3

I am trying to use concat_ws inside a group_concat command. With a query, which simplified looks like:

SELECT item.title, GROUP_CONCAT( CONCAT_WS(  ',', attachments.id, attachments.type,     attachments.name ) )  as attachments
FROM story AS item
LEFT OUTER JOIN story_attachment AS attachments ON item.id = attachments.item_id
GROUP BY item.id

I get the attachments column as a Blob type. is it it possible to get it as a string instead of Blob?

+1  A: 

Try here

ZombieSheep
+1  A: 

You need to cast as a char..

SELECT item.title, GROUP_CONCAT( CAST(CONCAT_WS(',', attachments.id, 
attachments.type, attachments.name ) as CHAR ) ) as attachments 
FROM story AS item 
LEFT OUTER JOIN story_attachment AS attachments 
ON item.id = attachments.item_id GROUP BY item.id
Wayne
you are missing one clammer SELECT item.title, GROUP_CONCAT( CAST( CONCAT_WS( ',', attachments.id, attachments.type, attachments.name ) AS CHAR ) ) AS attachmentsFROM story AS itemLEFT OUTER JOIN story_attachment AS attachments ON item.id = attachments.item_idGROUP BY item.idplease edit!
Sergio del Amo
Added.. thanks. :)
Wayne
A: 

Although I suspect CAST is the appropriate answer, it's worth mentioning that I ran into a similar thing in the past which turned out to be down to a strange/conflicting collation type and character set.

Draemon