rdbms » saveResult(db,sql,output)
Description
This command is similar to runSQL(var,db,sql)
, except that the query result is saved to
output
. The output will be in CSV format (comma to delimit fields, and \n
to delimit record). This can be
extremely useful for file comparison or post-query processing dealing with CSV. In addition to saving query output
to file, the metadata of the executed query is also saved to a JSON file corresponding to the specified output
.
For example,
Assuming that the query runs successfully, a MyResult.csv
will be created in the out
directory (as specified),
and a MyResult.json
(query metadata) will be created in the same directory.
Below is a snapshot of the output
CSV file generated via this command (comma-separated fields, newline-separated
records):
Query Metadata
The content of the query metadata differs by the query specified. In general, it contains the
Execution Result
but without the dataset. For example, the screenshot shows one such JSON containing:
- column names
- the sql that was executed
- the start time of such execution, in epoch
- the elapsed time, in millisecond, to complete the execution
- the number of rows returned via such execution
If the target query (denoted by sql
) results in multiple results, Nexial will create the corresponding
output file suffixed with the nested index. For example,
- suppose the specified
output
parameter is$(syspath|out|fullpath)/Result.csv
. - then, the output file for the first nested result would be
$(syspath|out|fullpath)/Result.0.csv
, and - the output file for the second nested result
$(syspath|out|fullpath)/Result.1.csv
, and so on.
Parameters
- db - the profile from which defines the
database connectivity details
. - sql - the query to execute. Note that if this query does not result in any dataset (such as a UPDATE or INSERT query), then only the result metadata file (JSON) will be generated.
- output - the target file to save the resulting dataset.