Bug #64600 group_concat seperator parameter doesn't accept concat() returned value
Submitted: 9 Mar 2012 9:56 Modified: 5 May 2012 15:27
Reporter: Nicolas Pow Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.5.20 OS:Any
Assigned to: Paul DuBois CPU Architecture:Any
Tags: concat, group_concat, SEPARATOR

[9 Mar 2012 9:56] Nicolas Pow
Description:
Hy everyone!

Please consider this code : SELECT GROUP_CONCAT(column SEPARATOR CONCAT(':',':'));

I know that GROUP_CONCAT(column SEPARATOR '::') works fine but i'm actually trying to go
deeper using the CONCAT function into the GROUP_CONCAT function. 

This exemple is not really what i want to do but it reveal the problem.

I'll try to express myself better :

As it is written in the documentation CONCAT function return a string and SEPARATOR is taking a string as argument.

So, why this way doesn't work?

Is this a bug or am I wrong somewhere?

I get error code : #1064 - You have an error in your SQL syntax;

How to repeat:
execute something like :

SELECT GROUP_CONCAT(column SEPARATOR CONCAT(':',':'));
[9 Mar 2012 10:59] Valeriy Kravchuk
This is easy to repeat, but our manual, http://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_group-concat, says:

"The full syntax is as follows:

GROUP_CONCAT([DISTINCT] expr [,expr ...]
             [ORDER BY {unsigned_integer | col_name | expr}
                 [ASC | DESC] [,col_name ...]]
             [SEPARATOR str_val])
"

Note "str_val" (and not just "str" or "expr") is used. So I'd say that string literal is assumed. This is what we have in sql_yacc.yy in the source code:

opt_gconcat_separator:
          /* empty */
          {
            $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
            if ($$ == NULL)
              MYSQL_YYABORT;
          }
        | SEPARATOR_SYM text_string { $$ = $2; }
        ;

See text_string above that is defined as:

text_string:
          TEXT_STRING_literal
...

We can make a feature request and/or documentation request out of this, but I think that formally it works as designed.
[9 Mar 2012 17:27] Nicolas Pow
Thanks you a lot for these precisions and the quick and complete answer.
[9 Mar 2012 17:49] Valeriy Kravchuk
Let's consider this as a documentation request. Manual should clearly say that string literal is expected.
[5 May 2012 15:27] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.