Just get column names from hive table

cantdutchthis picture cantdutchthis · Oct 3, 2014 · Viewed 109.4k times · Source

I know that you can get column names from a table via the following trick in hive:

hive> set hive.cli.print.header=true;
hive> select * from tablename;

Is it also possible to just get the column names from the table?

I dislike having to change a setting for something I only need once.

My current solution is the following:

hive> set hive.cli.print.header=true;
hive> select * from tablename;
hive> set hive.cli.print.header=false;

This seems too verbose and against the DRY-principle.

Answer

JJFord3 picture JJFord3 · Oct 8, 2014

If you simply want to see the column names this one line should provide it without changing any settings:

describe database.tablename;

However, if that doesn't work for your version of hive this code will provide it, but your default database will now be the database you are using:

use database;
describe tablename;