Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alias a column with identifier that contains spaces?

Tags:

sql

hive

Does anyone know the syntax for aliasing a column without underscores in Hive? In SQL and MYSQL you can use single quotes or brackets. This does not seem to work in Hive. Here a simple query that wouldn't work:

select inbound_handled as 'IB Handled' 
from shdev.cust_data     
like image 745
M Jennings Avatar asked Oct 16 '25 19:10

M Jennings


1 Answers

The syntax is:

select inbound_handled as `IB Handled` 
from shdev.cust_data     

In Hive release 0.12.0 and earlier, column names can only contain alphanumeric and underscore characters.

In Hive release 0.13.0 and later, by default column names can be specified within backticks (`) and contain any Unicode character (HIVE-6013). Within a string delimited by backticks, all characters are treated literally except that double backticks (``) represent one backtick character. The pre-0.13.0 behavior can be used by setting hive.support.quoted.identifiers to none, in which case backticked names are interpreted as regular expressions. See Supporting Quoted Identifiers in Column Names for details.

See docs here: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterColumn

like image 59
leftjoin Avatar answered Oct 18 '25 14:10

leftjoin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!