In Hive, when we do a query (like: select * from employee
), we do not get any column names in the output (like name, age, salary that we would get in RDBMS SQL), we only get the values.
Is there any way to get the column names to be displayed along with the output when you execute any query?
If we want to see the columns names of the table in HiveQl, the following hive conf property should be set to true.
If you prefer to see the column names always then update the $HOME/.hiverc file with the above setting in the first line..
--Hive automatically looks for a file named .hiverc in your HOME directory and runs the commands it contains, if any
To print header along with the output, the following hive conf property should be set to true before executing the query.
We can also use query like this, if we want to get result in file.
Where table_name your table name
Set this property before executing your query :
Most of the solutions are accurate.
setting the property
hive.cli.print.header = true
works.But if you are using a cloudera , HDP or any other distributions, these will be reset. Hence update these value in the Hive configurations and restart the services.
This will be a permanent fix. hope this helps.
Use
set hive.cli.print.header=true;
All above answers already answer the question. But in case if someone wants this property to be ON permanently, then there is this property:
hive.cli.print.header
inhive-default.xml
orhive-site.xml
.Its default value is false. Make its value as true and save. Done.