Hive - Concat String with row data

35,413

Use concat() function:

'SELECT concat('Select * from ', [table_name],  '; ') 
                 FROM your_table
                 ORDER BY [table_name]'

if a [table_name] is a column containing table_name

Share:
35,413
Pruthvi
Author by

Pruthvi

Updated on September 30, 2020

Comments

  • Pruthvi
    Pruthvi over 3 years

    Am trying to concat a string with data row in a table using Hive.

    which looks like this in SQL

     SELECT 'Select * from ' + [Column] + '; '
                     FROM table_name
                     ORDER BY [table_name]
    

    Result Should be - SELECT * FROM abc; SELECT * FROM asd; SELECT * FROM xyz ..

    Unable to write or find something related to this in Hive command.

  • Pruthvi
    Pruthvi over 8 years
    This format is not working. The problem here is "" Select * from "" is hard coded and [Column] is dynamic. Have to concat a hard coded string and data from a column dynamically.