codninja0908
codninja0908

Reputation: 567

How to pass tablename as parameter to Bigquery command line in shell script

#creating tables with schema only:

for f in $list;              
do           
echo "event name :::::$f"      
bq query --use_legacy_sql=False --destination_table dataset_name.$f  'select * from `project_id.dataset_name.$f` where 1=2'   
done         

The query statement is not considering $f as a parameter in select statement.

Upvotes: 0

Views: 2988

Answers (1)

Iñigo
Iñigo

Reputation: 2670

It's happening because of the ticks [ ' ] .

Here you have a working code (I used numbers):

for i in {1..3}
do
echo "TABLE $i"
bq query --use_legacy_sql=false 'select * from `<project>.<database>.'$i'`'
done

See how I separated the parameter $i with ticks [ ' ]. For your case it should be:

bq query --use_legacy_sql=False --destination_table dataset_name.$f  'select * from `project_id.dataset_name.'$f'` where 1=2'

Upvotes: 1

Related Questions