Mysql query vertical "\G" not working -
i have question query data vertical format, tried \g or \g .
i referenced "4.5.1.6.2 displaying query results vertically" @ https://dev.mysql.com/doc/refman/5.5/en/mysql-tips.html
but not working , show error syntax @ "\g"
my query :
select * mytable \g . wrong.
from that, want build final query this:
select "a","b","c","d" "columnname" \g
expect:
columnname b c d
i tried union or union all. several thousand record, it's slow performance.
and mysql version : server version- 5.6.17 - mysql community server (gpl)
@ bernd buffen
i show query:
select c.* ( ( select * (select "value1" newcolumn union select "value2" newcolumn union ...<200.000 union all>) ) left join (select key,column1,column2,colum3 supplier ) b on a.newcolumn = b.key ) c
and handle query database, debug time begin end, spend 1.30 2 minutes. not good.
the \g , \g features features of command line client (as mentioned in comments.)
mysql when used programming api (even program, phpmyadmin or mysql gui) not support \g or \g. doesn't "display" data. display done gui program, instead.
however, if ran query:
select 'a', 'b', 'c', 'd' "columnname"\g
in command line client, produce:
*************************** 1. row *************************** a: b: b c: c columnname: d 1 row in set (0.01 sec)
this because you've selected 4 columns in query, , named last 1 'columnname'.
if want see rows of table run:
select * table_name\g
and list each column, :
, value.
nevertheless, work command line client.
if you're wanting retrieve key, value database via programming api, problem bit trickier. union going end being want, e.g.:
select 'column_name_1' key, group_concat(column_name_1) value table_name union select 'column_name_2' key, group_concat(column_name_2) value table_name
but yes, it's not efficient.
this isn't way databases meant used - they're meant used table of data. i'd suggest change data format after you've retrieved mysql. might in array, or similar.
Comments
Post a Comment