Skip to content

sql

sql - execute SQL queries and scripts in dbvr.

Synopsis

dbvr sql [-hV]
         [-format=<outputFormat> | --output-format=<outputFormat>]
         [-in=<inputFile> | -input-file=<inputFile>]
         [-l=<limit> | --limit=<limit>]
         [-op=<outputFormatParameters> | --output-format-parameters=<outputFormatParameters>]
         [-out=<outputFile> | -output-file=<outputFile>]
         [-p=<dbPassword> | --password=<dbPassword>]
         [--project=<projectIdOrName>]
         [-token=<accessToken> | --access-token=<accessToken>]
         [-u=<dbUser> | --user=<dbUser>]
         [-auth=<authParams> | --auth-property=<authParams>]...
         [-ext=<providerParams> | --extended-property=<providerParams>]...
         [-prop=<connectionParams> | --property=<connectionParams>]...
         [[-net=<handlerParams> | --network-handler-param=<handlerParams>]...
          [-net-save-pwd=<savePassword> | --network-handler-save-password=<savePassword>]]
         (-ds=<existDataSourceIdOrName> | --datasource=<existDataSourceIdOrName> |
          -con=<connectionSpec> | -connect=<connectionSpec> | -ds-spec=<connectionSpec> | --datasource-specification=<connectionSpec> |
          [--driver=<driver>
            [[--host=<host>]
             [--database=<dbName>]
             [--server=<server>]
             [--url=<url>]
             [--auth-model=<authModel>]
             [--port=<port>]
             [--folder=<folder>]
             [--name=<dataSourceName>]
             [--save-password=<savePassword>]]])
         [<query>]

Tip

You can also use global options with this command.

Tip

SQL execution in dbvr follows the same engine and configuration model as in DBeaver. For UI-based query execution, result export, and execution settings, see SQL execution.

Description

Execute a SQL query or script.

You can connect in three ways:

  • use an existing datasource with -ds or --datasource
  • provide a full connection specification with -con, -ds-spec, -connect or --datasource-specification
  • define a connection inline using --driver and connection options

Required argument

<query>

SQL statement to execute.

If specified, it must be the last argument in the command. If omitted, SQL is read from standard input or from -in/-input-file.

Connection options

--datasource

--datasource, -ds=<existDataSourceIdOrName>

Use an existing datasource by ID or name.

Use datasource list to see available datasources.

Example

dbvr sql \
  -ds=pg-local \
  "select current_database();"

--datasource-specification

-con, -connect, -ds-spec, --datasource-specification=<connectionSpec>

Provide a full datasource specification string. The specification is a list of key=value pairs separated by |.

Example

dbvr sql \
  -con="driver=sqlite_ee|url=jdbc:sqlite:/path/to/Chinook.db" \
  "select count(*) from Album;"

--driver

Use this option when you want to define a connection inline instead of using an existing datasource.

When --driver is specified, you define the connection inline. Connection properties work the same way as in datasource create.

  • --host
  • --port
  • --database
  • --server
  • --url
  • --auth-model
  • -u, --user
  • -p, --password
  • --save-password
  • --folder
  • --name
  • --project

Example

dbvr sql \
  --driver=postgres-jdbc \
  --host=localhost \
  --port=5432 \
  --database=testdb \
  -u=admin \
  -p=password \
  "select * from public.orders limit 10;"

Authentication options

--auth-property

-auth, --auth-property=<authParams>

Add a driver-specific authentication parameter in key=value format. May be specified multiple times.

Example

dbvr sql \
  --driver=postgres-jdbc \
  --host=localhost \
  --database=testdb \
  --auth-model=ssl \
  -auth=ssl=true \
  -auth=sslmode=require \
  "select 1;"

--user

-u, --user=<dbUser>

Set the database username used for authentication.

--password

-p, --password=<dbPassword>

Set the database password.

Network options

--network-handler-param

-net, --network-handler-param=<handlerParams>

Configure a network handler parameter in key=value format. Used for SSH tunnels, proxies, or other network configurations. May be specified multiple times.

Parameter names must match the properties defined by the selected network handler. Use dbvr network-handlers to see available handler IDs and supported parameters.

Example (PostgreSQL via SSH tunnel)

dbvr sql \
  --driver=postgres-jdbc \
  --host=localhost \
  --port=5432 \
  --database=testdb \
  -u=admin \
  -p=password \
  -net=ssh.host=example.com \
  -net=ssh.port=22 \
  -net=ssh.user=app \
  -net=ssh.authType=PASSWORD \
  -net=ssh.password=secret \
  "select * from public.orders limit 10;"

Info

Use network-handlers to see supported handlers and parameters.

--network-handler-save-password

-net-save-pwd, --network-handler-save-password=<savePassword>

Control whether passwords defined in network handlers - such as SSH tunnels or proxy configurations - are stored in the workspace configuration. Accepts a boolean value. Default: true.

Driver and provider parameters

--property

-prop, --property=<connectionParams>

Add a driver connection property in key=value format. Passed directly to the JDBC driver for this execution. May be specified multiple times.

Example (JDBC driver property)

dbvr sql \
  --driver=postgres-jdbc \
  --host=localhost \
  --database=testdb \
  -u=admin \
  -p=password \
  --property=ssl=true \
  --property=applicationName=dbvr-cli \
  "select current_user;"

--extended-property

-ext, --extended-property=<providerParams>

Add a driver-specific parameter in key=value format. May be specified multiple times.

Used for additional driver properties that are not part of the authentication model.

Example (Snowflake warehouse)

dbvr sql \
  --driver=snowflake-jdbc \
  --host=account.snowflakecomputing.com \
  --database=TESTDB \
  -u=app \
  -p=secret \
  --extended-property=warehouse=COMPUTE_WH \
  "select current_warehouse();"

Input and output options

-input-file

-in, -input-file=<inputFile>

Read SQL from a file instead of passing a query argument.

--output-format

-format, --output-format=<outputFormat>

Write the execution result in a specific format.

Supported formats:

  • csv
  • txt
  • json
  • xml
  • html
  • md (markdown)
  • sql
  • php (source)
  • parquet
  • xlsx

Default: csv.

--output-format-parameters

-op, --output-format-parameters=prop1=value1,prop2=value2

Exporter options as a list of properties. Comma and space are delimiters.

Example

dbvr sql \
  --driver=sqlite_ee \
  --url=jdbc:sqlite:/path/to/Chinook.db \
  -format=csv \
  -op="delimiter=;" \
  -out=orders.csv \
  "select * from Album limit 3;"

-output-file

-out, -output-file=<outputFile>

Write the execution result to a file.

Example

dbvr sql \
  --driver=postgres-jdbc \
  --host=localhost \
  --port=5432 \
  --database=testdb \
  -u=admin \
  -p=password \
  -format=json \
  -out=path/to/orders.json \
  "select * from public.orders limit 10;"

Tip

Export formats and options use the same exporters as in DBeaver. For details on supported formats and configuration, see Data export.

Tip

You can write results not only to local files, but also to cloud storage if it’s configured. For example:

-out=gs://example-bucket/example/orders.csv

Supported cloud schemes depend on your environment configuration, for example s3:// or gs://. Credentials must be configured externally, for example using AWS CLI, gcloud CLI, or environment variables.

--limit

-l, --limit="[offset,]limit"

Limit the number of fetched rows and optionally set an offset. Default: 1000.

Example

dbvr sql \
  --driver=postgres-jdbc \
  --host=localhost \
  --port=5432 \
  --database=testdb \
  -u=admin \
  -p=password \
  -format=json \
  -l=20,10 \
  "select * from public.orders;"

Examples

Run a query using an existing datasource:

dbvr sql -ds=pg-local "select current_date;"

Run a script from a file:

dbvr sql -ds=pg-local -in=path/to/script.sql

Run with inline connection parameters:

dbvr sql \
  --driver=postgres-jdbc \
  --host=localhost \
  --database=testdb \
  -u=admin \
  -p=password \
  "select * from users;"

Export results to CSV:

dbvr sql \
  -ds=pg-local \
  -format=csv \
  -out=path/to/result.csv \
  "select * from users;"