Batch Processing with NuoDB SQL

The nuosql command line tool supports the following ways to batch process files:

  • Use the nuosql --file command line option

  • Redirect standard input (stdin) to nuosql

  • From within NuoDB SQL, execute a SQL file by specifying @filename

The following syntax lines execute SQL statements from a batch file named /my_path/my_batch_file.sql in a database named test:

$ nuosql test --user user_name --password password --file /my_path/my_batch_file.sql
$ nuosql test --user user_name --password password < /my_path/my_batch_file.sql
$ cat /my_path/my_batch_file.sql | nuosql test --user user_name --password password
$ nuosql test --user user_name --password password
SQL> @/my_path/my_batch_file.sql

When executing in batch mode, nuosql executes all of the SQL statements in the batch file. Any SQL statement errors are ignored. The nuosql command displays the output from the SQL statements to the screen.

If nuosql was started to perform the batch processing then nuosql exits after executing all statements in the file. If you invoke batch processing from within nuosql then the SQL> prompt appears when batch processing is complete.

By default, when executing batch files, nuosql suppresses the SQL> prompt from the display output. You can add a prompt to the output by specifying the --show-prompt option.

The following (my_nuodb.sql) is an example of a simple command file:

DROP TABLE t IF EXISTS;
CREATE TABLE t (x INTEGER);
INSERT INTO t VALUES (10);
INSERT INTO t VALUES (20);
SELECT * FROM t;

Run the SQL script as follows:

$ nuosql test --user user_name --password password --file my_nuodb.sql
DROP TABLE t IF EXISTS;
CREATE TABLE t (x INTEGER);
INSERT INTO t VALUES (10);
INSERT INTO t VALUES (20);
SELECT * FROM t;
 X
 --
 10
 20
$

Use the --show-prompt option to add the SQL> prompt to the output:

$ nuosql test --user user_name --password password --file my_nuodb.sql --show-prompt
SQL> DROP TABLE t IF EXISTS;
SQL> CREATE TABLE t (x INTEGER);
SQL> INSERT INTO t VALUES (10);
SQL> INSERT INTO t VALUES (20);
SQL> SELECT * FROM t;
 X
 --
 10
 20
SQL>
$