How do I escape reserved words used as column names on HIVE?

Kamleshkumar Gujarathi picture Kamleshkumar Gujarathi · Aug 25, 2017 · Viewed 7.4k times · Source

When I am executing following query in HIVE, it is giving me current date instead of the column values from USER_INFO table.

SELECT CURRENT_DATE 
FROM   USER_INFO
LIMIT 1; 

How do I escape reserved words used as column names on HIVE?

Thanks & Regards, Kamlesh

Answer

Kamleshkumar Gujarathi picture Kamleshkumar Gujarathi · Aug 25, 2017

Got it.

There are two ways

1 You can use apostrophe before and after the keyword as shown below.

SELECT CURRENT_DATE 
FROM   `USER_INFO`
LIMIT 1;

2 There is setting shown below which you can do if you are executing it with unix shell (i.e. with sh command)

hive.support.sql11.reserved.keywords=false

Hope this helps.

Thanks & Regards, Kamleshkumar Gujarathi