Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
865c482c
Commit
865c482c
authored
Aug 10, 2004
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge mysql.com:/home/wax/mysql/mysql-4.1
into mysql.com:/home/wax/mysql/mysql-4.1group_concat
parents
a11f0355
c1d49624
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
4 deletions
+80
-4
mysql-test/r/func_gconcat.result
mysql-test/r/func_gconcat.result
+30
-0
mysql-test/t/func_gconcat.test
mysql-test/t/func_gconcat.test
+35
-0
sql/item_sum.cc
sql/item_sum.cc
+15
-4
No files found.
mysql-test/r/func_gconcat.result
View file @
865c482c
...
@@ -321,3 +321,33 @@ HAVING LEFT(names, 1) ='J';
...
@@ -321,3 +321,33 @@ HAVING LEFT(names, 1) ='J';
names
names
John###Anna###Bill
John###Anna###Bill
DROP TABLE t1;
DROP TABLE t1;
CREATE TABLE t1 ( a int, b TEXT );
INSERT INTO t1 VALUES (1,'First Row'), (2,'Second Row');
SELECT GROUP_CONCAT(b ORDER BY b) FROM t1 GROUP BY a;
GROUP_CONCAT(b ORDER BY b)
First Row
Second Row
DROP TABLE t1;
CREATE TABLE t1 (a_id tinyint(4) NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES (1),(2),(3);
CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN (t2) on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
a_id b_list
1 1,2,3
2 4,5
3 NULL
DROP TABLE t2;
DROP TABLE t1;
CREATE TABLE t1 (A_ID INT NOT NULL,A_DESC CHAR(3) NOT NULL,PRIMARY KEY (A_ID));
INSERT INTO t1 VALUES (1,'ABC'), (2,'EFG'), (3,'HIJ');
CREATE TABLE t2 (A_ID INT NOT NULL,B_DESC CHAR(3) NOT NULL,PRIMARY KEY (A_ID,B_DESC));
INSERT INTO t2 VALUES (1,'A'),(1,'B'),(3,'F');
SELECT t1.A_ID, GROUP_CONCAT(t2.B_DESC) AS B_DESC FROM t1 LEFT JOIN t2 ON t1.A_ID=t2.A_ID GROUP BY t1.A_ID ORDER BY t1.A_DESC;
A_ID B_DESC
1 A,B
2 NULL
3 F
DROP TABLE t1;
DROP TABLE t2;
mysql-test/t/func_gconcat.test
View file @
865c482c
...
@@ -201,3 +201,38 @@ SELECT GROUP_CONCAT(a SEPARATOR '||') AS names FROM t1
...
@@ -201,3 +201,38 @@ SELECT GROUP_CONCAT(a SEPARATOR '||') AS names FROM t1
SELECT
GROUP_CONCAT
(
a
SEPARATOR
'###'
)
AS
names
FROM
t1
SELECT
GROUP_CONCAT
(
a
SEPARATOR
'###'
)
AS
names
FROM
t1
HAVING
LEFT
(
names
,
1
)
=
'J'
;
HAVING
LEFT
(
names
,
1
)
=
'J'
;
DROP
TABLE
t1
;
DROP
TABLE
t1
;
#
# check blobs
#
CREATE
TABLE
t1
(
a
int
,
b
TEXT
);
INSERT
INTO
t1
VALUES
(
1
,
'First Row'
),
(
2
,
'Second Row'
);
SELECT
GROUP_CONCAT
(
b
ORDER
BY
b
)
FROM
t1
GROUP
BY
a
;
DROP
TABLE
t1
;
#
# check null values #1
#
CREATE
TABLE
t1
(
a_id
tinyint
(
4
)
NOT
NULL
default
'0'
,
PRIMARY
KEY
(
a_id
))
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
latin1
;
INSERT
INTO
t1
VALUES
(
1
),(
2
),(
3
);
CREATE
TABLE
t2
(
b_id
tinyint
(
4
)
NOT
NULL
default
'0'
,
b_a
tinyint
(
4
)
NOT
NULL
default
'0'
,
PRIMARY
KEY
(
b_id
),
KEY
(
b_a
),
CONSTRAINT
fk_b_a
FOREIGN
KEY
(
b_a
)
REFERENCES
t1
(
a_id
)
ON
DELETE
CASCADE
ON
UPDATE
NO
ACTION
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
latin1
;
INSERT
INTO
t2
VALUES
(
1
,
1
),(
2
,
1
),(
3
,
1
),(
4
,
2
),(
5
,
2
);
SELECT
*
FROM
(
SELECT
t1
.*
,
GROUP_CONCAT
(
t2
.
b_id
SEPARATOR
','
)
as
b_list
FROM
(
t1
LEFT
JOIN
(
t2
)
on
t1
.
a_id
=
t2
.
b_a
)
GROUP
BY
t1
.
a_id
)
AS
xyz
;
DROP
TABLE
t2
;
DROP
TABLE
t1
;
#
# check null values #2
#
CREATE
TABLE
t1
(
A_ID
INT
NOT
NULL
,
A_DESC
CHAR
(
3
)
NOT
NULL
,
PRIMARY
KEY
(
A_ID
));
INSERT
INTO
t1
VALUES
(
1
,
'ABC'
),
(
2
,
'EFG'
),
(
3
,
'HIJ'
);
CREATE
TABLE
t2
(
A_ID
INT
NOT
NULL
,
B_DESC
CHAR
(
3
)
NOT
NULL
,
PRIMARY
KEY
(
A_ID
,
B_DESC
));
INSERT
INTO
t2
VALUES
(
1
,
'A'
),(
1
,
'B'
),(
3
,
'F'
);
SELECT
t1
.
A_ID
,
GROUP_CONCAT
(
t2
.
B_DESC
)
AS
B_DESC
FROM
t1
LEFT
JOIN
t2
ON
t1
.
A_ID
=
t2
.
A_ID
GROUP
BY
t1
.
A_ID
ORDER
BY
t1
.
A_DESC
;
DROP
TABLE
t1
;
DROP
TABLE
t2
;
sql/item_sum.cc
View file @
865c482c
...
@@ -1966,14 +1966,13 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
...
@@ -1966,14 +1966,13 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
Fix fields for select list and ORDER clause
Fix fields for select list and ORDER clause
*/
*/
for
(
i
=
0
;
i
<
arg_count
;
i
++
)
for
(
uint
i
=
0
;
i
<
arg_count
;
i
++
)
{
{
if
(
args
[
i
]
->
fix_fields
(
thd
,
tables
,
args
+
i
)
||
args
[
i
]
->
check_cols
(
1
))
if
(
args
[
i
]
->
fix_fields
(
thd
,
tables
,
args
+
i
)
||
args
[
i
]
->
check_cols
(
1
))
return
1
;
return
1
;
if
(
i
<
arg_count_field
&&
args
[
i
]
->
maybe_null
)
maybe_null
|=
args
[
i
]
->
maybe_null
;
maybe_null
=
0
;
}
}
result_field
=
0
;
result_field
=
0
;
null_value
=
1
;
null_value
=
1
;
max_length
=
group_concat_max_len
;
max_length
=
group_concat_max_len
;
...
@@ -1993,6 +1992,8 @@ bool Item_func_group_concat::setup(THD *thd)
...
@@ -1993,6 +1992,8 @@ bool Item_func_group_concat::setup(THD *thd)
uint
const_fields
;
uint
const_fields
;
byte
*
record
;
byte
*
record
;
qsort_cmp2
compare_key
;
qsort_cmp2
compare_key
;
Copy_field
*
ptr
;
Copy_field
*
end
;
DBUG_ENTER
(
"Item_func_group_concat::setup"
);
DBUG_ENTER
(
"Item_func_group_concat::setup"
);
if
(
select_lex
->
linkage
==
GLOBAL_OPTIONS_TYPE
)
if
(
select_lex
->
linkage
==
GLOBAL_OPTIONS_TYPE
)
...
@@ -2054,6 +2055,16 @@ bool Item_func_group_concat::setup(THD *thd)
...
@@ -2054,6 +2055,16 @@ bool Item_func_group_concat::setup(THD *thd)
key_length
=
table
->
reclength
;
key_length
=
table
->
reclength
;
record
=
table
->
record
[
0
];
record
=
table
->
record
[
0
];
/*
We need to store value of blob in buffer of a record instead of a pointer of
one.
*/
ptr
=
tmp_table_param
->
copy_field
;
end
=
tmp_table_param
->
copy_field_end
;
for
(;
ptr
!=
end
;
ptr
++
)
ptr
->
set
(
ptr
->
to_field
,
ptr
->
from_field
,
1
);
/* Offset to first result field in table */
/* Offset to first result field in table */
field_list_offset
=
table
->
fields
-
(
list
.
elements
-
const_fields
);
field_list_offset
=
table
->
fields
-
(
list
.
elements
-
const_fields
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment