Converting Data

Converting Data

gsqlcmd allows converting table data from local files and web resources.

The convert mode has the following form:

gsqlcmd convert [<input> [<output> [<output2>]]]

where input:


gsqlcmd supports the following input and output formats: plain text, HTML, XML, JSON, and CSV

Here are examples of the three basic forms:

gsqlcmd convert "" aapl.csv

gsqlcmd convert "" aapl.json aapl.csv

gsqlcmd convert aapl.json aapl.csv

In the first form, gsqlcmd downloads and converts data.

In the second form, gsqlcmd downloads data, saves the file, and converts data. You may use it to store files to reparse later.

In the third form, gsqlcmd converts the file.

You may customize parser and output options to get the required results.

For example, the following options add the Symbol column to the output and suppress the use of double quotes:

/add=Symbol=AAPL /quoteChar=

You may find a lot of ready-to-use samples in the Downloading and converting to CSV folder of the downloaded gsqlcmd package.


You may automate downloading and converting data.

For example, you may create a task file like symbols.txt:


The file contains the Symbol column. So, you may use its values in the {symbol} parameter.

Here is a simple batch file that downloads and converts 1-minute intraday stock prices from Yahoo Finance:

@echo off

set url="{symbol}?range=1d&interval=1m&indicators=quote&includeTimestamps=true"

gsqlcmd convert %url% src\{symbol}.JSON csv\*.CSV /taskfile=symbols.txt ^
        /add=Symbol={symbol} ^
        /quoteChar= /echoOutputFileName

See Using Batch Files and Tasks for details.


gsqlcmd supports a simple SELECT form in the input queries.

For example, the basic convert command produces the following result:

gsqlcmd convert aapl.json aapl.csv

200.3800;200.4500;199.68;200.3200;2019-04-09 13:30:00;1332001
200.6920;200.8850;200.32;200.3726;2019-04-09 13:31:00;351343

You may use the following command to add the symbol column, rename and reorder columns:

gsqlcmd convert "SELECT 'AAPL' AS symbol, timestamp AS time, open, high, low, close, volume FROM aapl.json" aapl.csv /quoteChar=

AAPL;2019-04-09 13:30:00;200.3200;200.4500;199.68;200.3800;1332001
AAPL;2019-04-09 13:31:00;200.3726;200.8850;200.32;200.6920;351343

Additional Notes

Use the make mode to generate SQL commands to import data to a database.

Also, you may use the import mode that combines the convert, make, exec modes.

This website is using cookies. By continuing to browse, you give us your consent to our use of cookies as explained in our Cookie Policy.OK