查询中的 MySQL group_concat_max_len

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6942901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:44:47  来源:igfitidea点击:

MySQL group_concat_max_len in a query

mysqlsql

提问by noktec

I'm searching a way to insert this

我正在寻找一种方法来插入这个

SET GLOBAL group_concat_max_len=15000

SET GLOBAL group_concat_max_len=15000

in an existing SQL query such as the following:

在现有的 SQL 查询中,例如:

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

但我无法让它工作,因为通常这个查询是自己执行的,我想知道你们中的一些人是否知道如何让它工作

采纳答案by Bill Karwin

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

您不能SET像正在执行的那样在表达式中使用语句,甚至不能在子查询中使用。SET单独执行in one 语句。您设置的值将影响后续语句。

By the way, are you aware that SET GLOBALmeans 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 SESSIONif you only want the value to affect your current session.

顺便说一句,您是否知道这SET GLOBAL意味着该设置会影响您服务器上的所有其他 MySQL 连接,并且该设置甚至会在您当前的会话完成后持续存在,直到您将其设置为其他内容?SET SESSION如果您只希望该值影响您的当前会话,您可能想要使用。

回答by Smith

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

CI3 示例,您不能将它们组合起来,但是您可以执行单独的查询,例如:

public function myModelFunction($id){

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

//actual query
$query= $this->db->query("").....

回答by Damodaran

The maximum allowed result length in bytes for the GROUP_CONCAT() function. The default is 1024. mysql> show variables like 'group%';

GROUP_CONCAT() 函数允许的最大结果长度(以字节为单位)。默认值为 1024。 mysql> show variables like 'group%';

You change the value of group_concat_max_len. Either in your config file or setting the session variable, e.g. "SET @@group_concat_max_len = 2048;'

您更改 group_concat_max_len 的值。在您的配置文件中或设置会话变量,例如“SET @@group_concat_max_len = 2048;”

回答by Stoyan Bozinov

You can execute them one after the other and I think that it will have the desired effect or separate the with a ; sign .

你可以一个接一个地执行它们,我认为它会产生预期的效果或者用 ; 分隔它们。标志 。

回答by hem

For new user, while searching for solution on increasing group_concat_max_len i identified that in certain cases variable was not defined in my.cnf file. Nothing to worry about just addup this variable group_concat_max_len=XXXXX under heading [mysqld] in my.cnf file and restart mysql... you are DONE !!!

对于新用户,在寻找增加 group_concat_max_len 的解决方案时,我发现在某些情况下变量未在 my.cnf 文件中定义。无需担心,只需在 my.cnf 文件中的 [mysqld] 标题下添加这个变量 group_concat_max_len=XXXXX 并重新启动 mysql...你就完成了!!!

XXXXX = you desired value eg: 2048,4096 etc.

XXXXX = 您想要的值,例如:2048,4096 等。