How to set global level group_concat_max_len in Flask-Sqlalchemy? - mysql

We are using group_concat in one of our query which returns string greater than default length of group_concat(1024). I need to set the max value for group_concat_max_len at the global level, but I am not able to find a way to achieve that in Flask_Sqlalchemy.
Request.query
.with_entities(func.group_concat(func.CONCAT_WS(';', Sample.xyz,Analysis.zy, Analysis.pqr).distinct()))
.outerjoin(Sample)
.outerjoin(Analysis)
.group_by(Request.id).all()
Let me know if anyone can help me with this.

set global group_concat_max_len=10000000;
run this

Related

Is there a way to get comma separated values of a column regardless of group_concat_max_len size?

I need to get the contents of a column as a comma-separated list.
SELECT GROUP_CONCAT(column) FROM table;
does the job but the table is very large and the default value for
group_concat_max_len is 1024.
SET GLOBAL group_concat_max_len = 999999;
I tried that to increase the size but it is not allowed because the app is running on a shared server and I don't have the privilege. What else can I try, please?
You can increase the group_concat_max_len per session instead. You will have the rights for that.
SET SESSION group_concat_max_len = 999999;
read more about it in the manual

Alternative to MySQL's GROUP_CONCAT function

I'm retrieving the data with MySQL function called "GROUP_CONCAT()".
But when I checked the result of "GROUP_CONCAT()" function related column, it was missing some data.
When I google the record missing issue with "GROUP_CONCAT()" function, in the official MySQL site they have mentioned as,
There is a global variable called group_concat_max_len and it will permit the maximum result length in bytes for the GROUP_CONCAT() function, the default value of it as 1024.
Therefore it seems I have to increase that value with following MySQL command,
SET GLOBAL group_concat_max_len = 1000000;
Therefore set this value permanently, I have to edit the MySQL server related configuration file (my.cnf or my.ini) and have to restart the server.
But unfortunately I haven't any permission to do so.
Therefore can you please help me to find out some alternative solution to fix this issue.
Thanks a lot.
Use SET SESSION instead:
SET SESSION group_concat_max_len = 1000000;
Unlike SET GLOBAL, SET SESSION does not require super privilege.
Reference

What is the maximum allowance for group_concat_max_len in MySQL?

I am using a group_concat to concatenate a lot of rows into one.
I set group concat to 10000 using:
SET group_concat_max_len = 10000;
But even then, my output cells remain incomplete and end with ...
I tried setting group_concat_max_len = 20000 and even that didn't help.
I also tried setting group_concat_max_len to 99999999. It still doesn't complete my output text. And I checked one of the group concat stops at Length = 230 characters and then gives ...
Is there any other way?
Check out this link: https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_group_concat_max_len
All the MySQL configuration variables are documented on that page, with details like minimum, maximum, default value, whether you can set them globally or per-session, whether you can change them on a running instance or does it require a restart, and other description of usage.
The maximum value for group_concat_max_len is 18446744073709551615.
The group-concat string does not end with "..." If you try to group too much text, it just gets truncated. So I wonder if the problem is not with MySQL's settings, but with the display of your cells.
For 32bit systems, the maximum value is 4294967295
For 64 bit systems, the maximum value is 18446744073709551615.
You can set the variable for your current session using
SET SESSION group_concat_max_len=4294967295;
To set the variable forever use
SET GLOBAL group_concat_max_len=4294967295;
(see http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_group_concat_max_len)

mysqli Stored Proc Cross tab [duplicate]

Following this post: POST ABOUT CONCAT
My problem is that i have many rows CONCAT into one row. For example if i have 10 rows with string around 50 chars, my query will show me only 6-7 of that rows or something like that.
I searech in stack and google and i found that i can change CONCAT max length by command: SET group_concat_max_len := ##max_allowed_packet. What i am doing wrong?
EDIT:
When i SHOW VARIABLES LIKE 'group_concat_max_len' it's shows me 1024.
Mysql version 5.0.96-log. Tables type: MyISAM. Looks like it dont have any limits, i try to select simple varchar with 2000 chars, and it looks fine.
I have 3 tables: 1st - Item with ItemID, 2nd - Descriptionpack with ItemID and DescriptionID, 3rd Description with DescriptionID.
Select
DISTINCT Item.ItemID as item
,GROUP_CONCAT(Description.DescriptionID) AS description
From Item
LEFT OUTER JOIN descriptionpack
on Item.ItemID=descriptionpack.ItemID
LEFT OUTER JOIN description
on descriptionpack.descriptionID=description.descriptionID
GROUP BY item
EDIT2: I think i found the problem, i said my problem to my provider and they answer me this:
I reviewed your question with our hosting team. You wouldn't be able
to change the global settings for that and other variables. However,
you should be able to set that variable on a per session basis by
setting it first, before other queries. Hope that helps.
So now the problem is, how to do that.
Presumably you're using GROUP_CONCAT(), not simple CONCAT().
The default value of the group_concat_max_len is 1024, which is a pretty small limit if you're building up big long concatenations.
To change it, use this command. I've set the length in this example to 100,000. You could set it to anything you need.
SET SESSION group_concat_max_len = 100000;
The usual value for max_allowed_packet is one megabyte, which is likely more than you need.
group_concat_max_len itself has an effectively unlimited size. It's limited only by the unsigned word length of the platform: 2^32-1 on a 32-bit platform and 2^64-1 on a 64-bit platform.
If that still isn't enough for your application, it's time to take #eggyal's suggestion and rethink your approach.
You need change group_concat_max_len default value in the bellow config file
**my.cnf file(Linux) and my.ini file(windows)**
[mysqld]//Add this line group_concat_max_len=15000 under mysqld section
group_concat_max_len=15000
Note: After change is done You need to restart your MySQL server.
my.cnf file path in linux :
1. /etc/my.cnf
2./etc/mysql/my.cnf
3.$MYSQL_HOME/my.cnf
4.[datadir]/my.cnf
5.~/.my.cnf

Getting maximum value from a column in a MySQL table, increasing value by 1 and passing to variable

I am using the query below to extract the maximum value of a column called id in a MySQL table, so that I can increase it's value by 1 and pass it to a variable called $fav_id. For some reason $fav_id is returning '0', instead of the value I want, i.e. if the maximum current value in the id column is 465, then $fav_id should be set to 466. Perhaps someone could let me know where I am going wrong.
$sth2 = $pdo->prepare("SELECT MAX(id) AS id FROM tracks");
$sth2->setFetchMode(PDO::FETCH_OBJ);
while($row = $sth2->fetch()) {
$fav_id = $row->id+1;
}
Try wrapping $row->id+1 in parenthesis, like ($row->id)+1, and keep an eye out for scoping. You might want to set $fav_id to 0 outside of the while loop to establish it has a larger scope then just the while loop.
From my knowledge of PDOs, it should be $row[id] not $row->id. Also, you never executed the prepared statement, but since you don't have any placeholders in the query you should use '->query' instead of '->prepare'