kwil-cli exec-sql
kwil-cli exec-sql
Execute SQL against a database
Synopsis
Execute SQL statements against a database.
This command executes SQL and DDL statements against a database. It is meant to be used for statements that do not return data, such as INSERT, UPDATE, DELETE, CREATE TABLE, etc. For SELECT statements, use the 'query' command.
This command requires a private key. Each statement issued will use the private key to author a transaction to the network.
kwil-cli exec-sql [flags]
Examples
# Execute a create table statement
kwil-cli exec-sql "CREATE TABLE my_table (id int primary key, name text)"
# Execute a create table statement from a file
kwil-cli exec-sql --file /path/to/file.sql
# Execute an insert statement with parameters
kwil-cli exec-sql "INSERT INTO my_table (id, name) VALUES ($id, $name)" --param id:int=1 --param name:text=foo
# Execute an insert with a NUMERIC parameter (note the quotes)
kwil-cli exec-sql "INSERT INTO balances (account, amount) VALUES ($acc, $amt)" --param acc:text=user1 --param 'amt:numeric(78,0)=1000.5'
When using parameters with special characters like parentheses (e.g., numeric(10,5), arrays with []),
always wrap the parameter in quotes to prevent shell interpretation:
# Correct - with quotes
kwil-cli exec-sql "INSERT INTO t (val) VALUES ($v)" --param 'v:numeric(78,0)=1000'
# Incorrect - without quotes (will cause shell errors)
kwil-cli exec-sql "INSERT INTO t (val) VALUES ($v)" --param v:numeric(78,0)=1000
This applies to all shells (bash, zsh, fish, etc.) and is especially important for:
- NUMERIC types with precision/scale:
numeric(precision,scale) - Array types:
text[],int[],numeric(10,5)[] - Complex array values:
[value1, value2]
Use single quotes ('...') for simplicity, or double quotes ("...") if you need variable expansion.
Options
-f, --file string the file containing the SQL statement(s) to execute
-h, --help help for exec-sql
-N, --nonce int nonce override (-1 means request from server) (default -1)
-p, --param stringArray the parameters to pass to the SQL statement. format: "key:type=value"
-s, --stmt string the SQL statement to execute
--sync synchronous broadcast (wait for it to be included in a block)
Options inherited from parent commands
-Y, --assume-yes Assume yes for all prompts
--chain-id string the expected/intended Kwil Chain ID
-c, --config string the path to the Kwil CLI persistent global settings file (default "/Users/brennanlamey/.kwil-cli/config.json")
--output string the format for command output - either 'text' or 'json' (default "text")
--private-key string the private key of the wallet that will be used for signing
--provider string the Kwil provider RPC endpoint (default "http://127.0.0.1:8484")
-S, --silence Silence logs
SEE ALSO
- kwil-cli - Command line interface client for using Kwil.