简体   繁体   中英

Hive - Concat String with row data

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.

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

Concate the string data which is in row. Say x , y to be the column names.

insert into orders(1,"a");
insert into orders(2,"b");

Here suppose we want to concate "a" , "b" as one entity. So we do as follow

select concat_ws(',',collect_list(a,b)) from orders;

You can use concat to accomplish your task. But if you directly put ";" inside concat function it may show "can not recognize input error" to avoid this use \ before;

below is the tested and working example of the same

select concat("select * from ", col , " \;") from table

output:

select * from A;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM