0

In Groovy, I want to be able to execute a truncate query dynamically. However, I know the following won't work as ${s}.${x} needs to be interpolated before being sent to sql.execute. But what is the best and safest method to be able to run the below?

for (String s : schema) {
  for (String x : table) {
    try {
      sql.execute "TRUNCATE ${s}.${x}" ;
    } catch (Exception e) {
      println e
    }
  }
}
1
  • 3
    What makes you think ${s}.${x} is not interpolated before being sent to sql.execute()? What happens when you run that code?
    – JB Nizet
    Oct 21, 2017 at 12:55

1 Answer 1

0
sql.execute( "TRUNCATE ${s}.${x}".toString())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.