'How to group concat all column names in MySQL
I have a table having 122 columns, but when I try to group concat the column names, not all columns are joined together, only 35 columns are joined.
Additionally, the last column name appearing from the query of the group_concat does not get outputted correctly i.e instead of it being recurring_moratorium_principal it's appearing as recurring_moratorium_prin
select
group_concat(column_name SEPARATOR ',') as create_qry
from
(
select
table_name,
column_name,
data_type,
concat(
case
when data_type like '%int%' then 'int_c'
when data_type like '%text%' then 'str_c'
when data_type like '%character varying%' then 'str_c'
when data_type like '%uuid%' then 'str_c'
when data_type like '%double%' then 'float_c'
when data_type like '%boo%' then 'boo_c'
when data_type like '%timestamp%' then 'ts_c'
when data_type like '%numeric%' then 'num_c'
when data_type like '%decimal%' then 'float_c'
when data_type = 'date' then 'd_c'
when data_type like '%ARRAY%' then 'str_c'
when data_type like '%tsrange%' then 'int_c'
when data_type like '%real%' then 'float_c'
else 'str_c'
end,
' as ',
Case
When column_name = 'group' then 'my_group'
else column_name
end
) as type
from
information_schema.COLUMNS
where
table_name = 'city')a
The result of above query i.e create_qry looks like
int_c as id, <columns name between 2-34>, int_c as recurring_moratorium_prin
What I'm I missing?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
