It is possible to get a list of column names for any table.
This method will also work for TEMPORARY tables:
SET @columns_string = ''
;
SHOW
COLUMNS
FROM
`mysql`.`user`
WHERE
@columns_string := CONCAT(`Field`, ',', @columns_string)
;
SELECT @columns_string
;
@columns_string
will have a value of:
account_locked,password_lifetime,password_last_changed,password_expired,authentication_string,plugin,max_user_connections,max_connections,max_updates,max_questions,x509_subject,x509_issuer,ssl_cipher,ssl_type,Create_tablespace_priv,Trigger_priv,Event_priv,Create_user_priv,Alter_routine_priv,Create_routine_priv,Show_view_priv,Create_view_priv,Repl_client_priv,Repl_slave_priv,Execute_priv,Lock_tables_priv,Create_tmp_table_priv,Super_priv,Show_db_priv,Alter_priv,Index_priv,References_priv,Grant_priv,File_priv,Process_priv,Shutdown_priv,Reload_priv,Drop_priv,Create_priv,Delete_priv,Update_priv,Insert_priv,Select_priv,User,Host,
The problem with this solution (besides needing to parse a string) is that the SHOW COLUMNS
command will always generate an (empty) resultset.
This means that you can't really use this method in a stored procedure that returns a SELECT (you will end up with more than one resultset).