Repository navigation
sql
sql - execute SQL queries and scripts in dbvr.
dbvr sql [-hV]
[-format=<outputFormat> | --output-format=<outputFormat>]
[-in=<inputFile> | -input-file=<inputFile>]
[--print-queries]
[--disable-status]
[-l=<limit> | --limit=<limit>]
[-op=<outputFormatParameters> | --output-format-parameters=<outputFormatParameters>]
[-out=<outputFile> | -output-file=<outputFile>]
[--output-log=<format>]
[-p=<dbPassword> | --password=<dbPassword>]
[--project=<projectIdOrName>]
[-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.
Execute a SQL query or script.
Tip: To inspect database objects before running SQL queries, use
meta.
<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.
Use connection settings to specify which database this command runs against.
Connect in one of these ways:
- use an existing datasource with
-dsor--datasource - provide a full connection specification with
-con,-ds-spec,-connect, or--datasource-specification - define a connection inline with
--driverand connection parameters
You can also provide credentials, network handlers, and driver-specific properties.
For details on all connection settings, see Connection options.
-in, -input-file=<inputFile>
Read SQL from a file instead of passing a query argument.
Example:
Run an existing SQL file. Replace
CONNECTION_NAMEwith an existing datasource ID or name andABSOLUTE_FILE_PATHwith the full absolute path to your SQL file:dbvr sql -ds="CONNECTION_NAME" -in="ABSOLUTE_FILE_PATH"
Tip: You can read scripts not only from local files, but also from cloud storage. For configuration, see Configure cloud providers. For usage examples, see Use cloud storage in SQL commands.
--print-queries
Print each SQL query above its result in the output.
Example:
dbvr sql \ --driver=postgres-jdbc --host=localhost --port=5432 --database=postgres \ --print-queries \ "SELECT id, name FROM (VALUES (101, 'John Doe'), (102, 'Maya Chen')) AS c(id, name) WHERE name = 'John Doe';"Output (execution time varies):
SELECT id, name FROM (VALUES (101, 'John Doe'), (102, 'Maya Chen')) AS c(id, name) WHERE name = 'John Doe' |id |name | |---|--------| |101|John Doe| Rows read: 1, (82ms)
--disable-status
Turn off the status line that normally follows each result (row count and execution time).
Use this when you're piping output into another tool and don't want the extra line mixed in.
Example:
dbvr sql \ --driver=postgres-jdbc --host=localhost --port=5432 --database=postgres \ --disable-status \ "SELECT id, name FROM (VALUES (101, 'John Doe'), (102, 'Maya Chen')) AS c(id, name) WHERE name = 'John Doe';"Output:
|id |name | |---|--------| |101|John Doe|
-format, --output-format=<outputFormat>
Write the execution result in a specific format.
Supported formats:
csvtxtjsonxmlhtml-
md(markdown) sql-
php(source) parquetxlsxdbunit
Default: txt.
Example:
Use
-format=jsonwith--disable-statusto return the query result as pure JSON:dbvr sql \ --driver=postgres-jdbc --host=localhost --port=5432 --database=postgres \ -format=json --disable-status \ "SELECT product, total FROM (VALUES ('Aurora Desk Lamp', 89.98::numeric), ('Harbor Ceramic Mug', 52.00::numeric)) AS o(product, total);"
-op, --output-format-parameters=prop1=value1,prop2=value2
Exporter options as a list of properties. Comma and space are delimiters.
Example:
dbvr sql \ --driver=postgres-jdbc --host=localhost --port=5432 --database=postgres \ -format=csv \ -op='delimiter=;' \ "SELECT product, total FROM (VALUES ('Aurora Desk Lamp', 89.98::numeric), ('Harbor Ceramic Mug', 52.00::numeric)) AS o(product, total);"CSV output excerpt (status line omitted):
"product";"total" Aurora Desk Lamp;89.98 Harbor Ceramic Mug;52.00
-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. For configuration, see Configure cloud providers. For usage examples, see Use cloud storage in SQL commands.
--output-log=<format>
Set the status output format: text (default) or json. Use json when a script or pipeline needs to parse the result
instead of scanning text with grep or awk.
Example:
dbvr sql \ --driver=postgres-jdbc --host=localhost --port=5432 --database=postgres \ --output-log=json \ "SELECT product, total FROM (VALUES ('Aurora Desk Lamp', 89.98::numeric), ('Harbor Ceramic Mug', 52.00::numeric)) AS o(product, total);"Status output appears before the two-row result table. Execution time varies:
{"status":"ok","rows":2,"durationMs":144} |product |total| |------------------|-----| |Aurora Desk Lamp |89.98| |Harbor Ceramic Mug|52 |
-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=postgres \ -l=1,2 \ "SELECT id, name FROM (VALUES (101, 'John Doe'), (102, 'Maya Chen'), (103, 'Ana Silva')) AS c(id, name) ORDER BY id;"Skip the first row and return the next two. Result rows (status line omitted):
|id |name | |---|---------| |102|Maya Chen| |103|Ana Silva|
Run a query using an existing PostgreSQL datasource named pg-local:
dbvr sql -ds=pg-local "SELECT id, name FROM (VALUES (101, 'John Doe'), (102, 'Maya Chen')) AS c(id, name) WHERE name = 'John Doe';"Run an existing SQL file using the placeholders described in the -input-file example:
dbvr sql -ds="CONNECTION_NAME" -in="ABSOLUTE_FILE_PATH"
Run with inline connection parameters:
dbvr sql \
--driver=postgres-jdbc \
--host=localhost \
--port=5432 \
--database=postgres \
"SELECT id, name FROM (VALUES (101, 'John Doe'), (102, 'Maya Chen')) AS c(id, name) WHERE name = 'John Doe';"Export results to CSV:
dbvr sql \
-ds=pg-local \
-format=csv \
-out=path/to/result.csv \
"select * from users;"
Write query results to Azure Blob Storage:
dbvr sql \
-ds=postgres \
-out=azb:///output.txt?endpoint=https://myaccount.blob.core.windows.net \
-format=txt \
"select * from orders;"
Read a script from Google Cloud Storage and write results back:
dbvr sql \
-ds=postgres \
-in=gs://my-bucket/script.sql \
-out=gs://my-bucket/output.txt \
-format=txt
Read a script from Amazon S3 and write results back:
dbvr sql \
-ds=postgres \
-in=s3:///my-bucket/script.sql \
-out=s3:///my-bucket/output.txt \
-format=txt
- Getting started
- Reference
- Commands
- Connection options
- Databases support
- Administration
- About dbvr
- Development