Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL group_concat_max_len in a query

Tags:

sql

mysql

I'm searching a way to insert this

SET GLOBAL group_concat_max_len=15000

in an existing SQL query such as the following:

SELECT * 
FROM `Pages` 
WHERE id =1 
UNION SELECT 1 , 2, IF( 1 >0, SET GLOBAL group_concat_max_len=15000,'B' ) 

But I couldn't make it work because usually this query is executed on its own and I was wondering if some of you had any idea how to make it work

like image 280
noktec Avatar asked Aug 04 '11 14:08

noktec


People also ask

What is Group_concat_max_len in MySQL?

As MySQL Blog by @Shlomi Noach Here group_concat_max_len : This parameter limits the maximum text length of a GROUP_CONCAT concatenation result. It defaults to 1024 .

Does GROUP_ CONCAT has limit?

Show activity on this post. I'm using GROUP_CONCAT() in a MySQL query to convert multiple rows into a single string. However, the maximum length of the result of this function is 1024 characters.


2 Answers

You can't use a SET statement inside an expression like you're doing, or even in a subquery. Execute the SET in one statement by itself. The value you set will affect subsequent statements.

By the way, are you aware that SET GLOBAL means the setting will affect all other MySQL connections on your server, and the setting will even persist after your current session is done, until you set it to something else? You might want to use SET SESSION if you only want the value to affect your current session.

like image 184
Bill Karwin Avatar answered Oct 02 '22 07:10

Bill Karwin


CI3 Example, you cant combine them, but you can execute a seperate query, such as:

public function myModelFunction($id){

//set mysql session variable
$this->db->query("SET @@group_concat_max_len = 2048;");

//actual query
$query= $this->db->query("").....
like image 28
Smith Avatar answered Oct 02 '22 07:10

Smith