I defined a named Arel function for MariaDB's GROUP_CONCAT
ta = Arel::Table.new 'authors'
Arel::Nodes::NamedFunction.new( 'GROUP_CONCAT', [ta[:name]] ).to_sql
This generates:
"GROUP_CONCAT(`authors`.`name`)"
I like however to define the separator option to generate the following output:
"GROUP_CONCAT(`authors`.`name` SEPARATOR '|' )"
I tried a number of approaches, for example
Arel::Nodes::NamedFunction.new( 'GROUP_CONCAT', [ ta[:name]], "SEPERATOR |" ).to_sql
Doesn't work since it creates the following SQL snippet:
GROUP_CONCAT(`authors`.`name`) AS SEPERATOR '|'
How do I need to specify the parameters for the desired output?
Many thanks :)
you nearly had it. All of the arguments go into the array (second argument). AFAIK, Arel has always been considered a private API, so documentation is pretty sparse.
Arel::Nodes::NamedFunction.new('GROUP_CONCAT', [ta[:name], Arel.sql("SEPARATOR '|'")]).to_sql