I'm operating on a Windows Machine, trying to export the results of a query by running SQL Workbench in Batch mode. After reading the SQL Workbench documentation, it sounds like WbExport is the best command for exporting results from a query.
Another requirement is the query I want to run is in an external .sql file. Again, according the SQL documentation, in batch mode, I can either use the WbInclude command or -script parameter to run a query from an external .sql file. However, I'm not able to get either of these to work correctly with WbExport. I've tried running SQL Workbench in Batch mode using both sqlwbconsole64.exe and sqlworkbench.jar. Please see the four examples below:
java -jar sqlworkbench.jar -profile='connection-profile' -command='WbExport -file=test_export.txt -type=text -delimiter=\t; WbInclude test.sql;'
java -jar sqlworkbench.jar -profile='connection-profile' -command='WbExport -file=test_export.txt -type=text -delimiter=\t' -script='test.sql'
sqlwbconsole64 -profile='connection-profile' -command='WbExport -file=test_export.txt -type=text -delimiter=\t; WBInclude test.sql;'
sqlwbconsole64 -profile='connection-profile' -command='WbExport -file=test_export.txt -type=text -delimiter=\t' -script='test.sql'
Thanks in advance for your help!
You can not use WbInclude
as the "source" for the WbExport command. You need to put everything into a single SQL script:
File export.sql
:
WbExport -file=test_export.txt -type=text -delimiter=\t;
select *
from the_table;
Or if you just want to export a single table, use:
WbExport -file=test_export.txt -type=text -delimiter=\t -sourceTable=the_table;
Then run
java -jar sqlworkbench.jar -profile='connection-profile' -script=export.sql
(Btw: if -script
is specified, -command
is ignored)