Comprehensive Guide to gsqlcmd SQL Options

Comprehensive Guide to gsqlcmd SQL Options

/columnNameQuote=[<quote>]

Use this option to set or disable column name quotes in generated SQL commands.

By default, gsqlcmd uses server-specific quotes: square brackets for SQL Server, backticks for MySQL, and double quotes for other servers.

/[commands=]insert | update | delete | merge

Specify the generated commands in the make and import modes.

For example:

gsqlcmd make yahoo.db 1min-aapl.csv *-insert.sql /insert /table=yahoo1min /echoOutputFileName
gsqlcmd make yahoo.db 1min-aapl.csv *-update.sql /update /table=yahoo1min /echoOutputFileName
gsqlcmd make yahoo.db 1min-aapl.csv *-delete.sql /delete /table=yahoo1min /echoOutputFileName
gsqlcmd make yahoo.db 1min-aapl.csv *-merge.sql  /merge  /table=yahoo1min /echoOutputFileName

The default option is /insert.

Use the /insert option (or omit it) to generate commands for executing stored procedures or custom code.

For example:

gsqlcmd make yahoo.db 1min-aapl.csv *-custom.sql /insert /table=custom-code.sql /echoOutputFileName

You can define columns used in the WHERE clause with the /keys option, like this:

gsqlcmd make yahoo.db 1min-aapl.csv *-insert.sql /insert /table=yahoo1min /echoOutputFileName
gsqlcmd make yahoo.db 1min-aapl.csv *-update.sql /update /table=yahoo1min /echoOutputFileName /keys=symbol,time
gsqlcmd make yahoo.db 1min-aapl.csv *-delete.sql /delete /table=yahoo1min /echoOutputFileName /keys=symbol,time
gsqlcmd make yahoo.db 1min-aapl.csv *-merge.sql  /merge  /table=yahoo1min /echoOutputFileName /keys=symbol,time

/groupSize=<number of rows>

Define the number of rows separated by the GO batch separator with this option.

/insertIdentity

Include identity columns in INSERT and MERGE commands generated in the make and import modes by using this option.

/insertNulls

Keep NULL values in INSERT commands generated in the make and import modes with this option.

/keys=<field>[;...]

Define primary key fields in the make-create mode with this option.

For example:

gsqlcmd make-create data.csv create-table.sql /table=dbo.data /mssql /keys=FirstName,LastName

You can also use this option to specify fields for the WHERE clause in generated UPDATE and DELETE commands in the make and import modes.

For instance, synchronize data between different databases using fields like email or SSN instead of primary key fields:

gsqlcmd make db emails.csv merge.sql /merge /table=dbo.emails /keys=email

/objectNameQuote=[<quote>]

Set or disable object name quotes in generated SQL commands with this option.

gsqlcmd uses server-specific quotes by default: square brackets for SQL Server, backticks for MySQL, and double quotes for other servers.

/printTotals[=true | false]

Add a line with the total count of generated SQL commands using this option.

/table=<table | view | stored procedure | SQL template file>

Define the target database table, view, stored procedure, or SQL template file for code generation with this option.

For example:

gsqlcmd make db data.csv insert.sql /insert /table=dbo.payments

This option is mandatory in the import, make, and make-create modes.

/truncate

Use the truncate() method instead of delete() in the Knex seed files generated in the make mode with this option.

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.