Shell script - psql run multiple statements from a variable one by one in one transaction
Yes, we can do it. 


echo the variable and then pipe it to psql.


echo "$analyze_query"  |  psql -h host -U user -d db 


Use () to group the command output then pipe it to psql.


(for i in $analyze_query 
do
 echo $i
done ) |  psql -h host -U user -d db