0

I'm writing a simple database migration code in clojure using the new seancorfield/next.jdbc library.

How do I execute several SQL statements at once? The usecase is that I have a SQL file containing query code for migrating from one version to the next. next.jdbc/execute! only executes one statement as designed.

mike3996
  • 17,047
  • 9
  • 64
  • 80

1 Answers1

5

Whether you can execute multiple statements in a single JDBC operation is database-dependent. Some databases allow multiple statements in a single operation, separated by a semicolon. If the JDBC driver supports it, next.jdbc will also support it.

If your JDBC driver does not support it, you'll need to make multiple execute! calls. Some databases allow you to wrap multiple DDL operations in a transaction (some of them ignore the transaction and commit each DDL operation separately anyway), some databases explicitly disallow a transaction around DDL operations.

Sean Corfield
  • 6,297
  • 22
  • 31