Hive query select as alias and format date

select as alias

In Hive, in order to use select COL as “Alias” syntax, we cannot use single or double quote. We have to use the special “backtick” symbol -> `

Example: SELECT user_name AS `system user name`, …..

date format

To format date, we need to convert the date to bigint with unix_timestamp function and then convert back using from_unixtime function.

example :

FROM_UNIXTIME(unix_timestamp(TRD_DT), 'MM/dd/yyyy') AS `Trade Date`

Comparing to all these, presto is quite straightforward, alias just need to be wrapped in the double quotes, and format date just using the DATE_FORMAT(date, format) function.

 

Leave a comment