Running a script
You can use the scripting yql
subcommand to run a YQL script. The script can include queries of different types. Unlike yql
, the scripting yql
command has a limit on the number of returned rows and accessed data.
General format of the command:
ydb [global options...] scripting yql [options...]
global options
: Global parameters.options
: Parameters of the subcommand.
View the description of the YQL script command:
ydb scripting yql --help
Parameters of the subcommand
Name |
Description |
|
The time within which the operation should be completed on the server. |
|
Statistics mode.
|
|
Text of the YQL query to be executed. |
|
Path to the text of the YQL query to be executed. |
|
Show the query execution plan. |
|
Show the response metadata. |
|
Result format.
|
Working with parameterized queries
A brief help is provided below. For a detailed description with examples, see Running parametrized YQL queries and scripts.
Name | Description |
---|---|
-p, --param |
The value of a single parameter of a YQL query, in the format: $name=value , where $name is the parameter name and value is its value (a valid JSON value). |
--param-file |
Name of the file in JSON format and in UTF-8 encoding that specifies values of the parameters matched against the YQL query parameters by key names. |
--input-format |
Format of parameter values. Applies to all the methods of parameter transmission (among command parameters, in a file or using stdin ).Acceptable values: |
--stdin-format |
The parameter format and framing for stdin . To set both values, specify the parameter twice.Format of parameter encoding for stdin Acceptable values:
stdin isn't specified, the format set in --input-format is used.Classification of parameter sets for stdin (framing)Acceptable values:
|
--stdin-par |
The name of the parameter whose value will be sent over stdin is specified without a $ . |
--batch |
The batch mode of transmitting parameter sets received via stdin .Acceptable values:
|
--batch-limit |
A maximum number of sets of parameters per batch in the adaptive batch mode. The setting of 0 removes the limit.The default value is 1000 . |
--batch-max-delay |
The maximum delay related to processing the resulting parameter set in the adaptive batch mode. It's set as a number of s , ms , m .Default value: 1s (1 second). |
Examples
Note
The examples use the quickstart
profile. To learn more, see Creating a profile to connect to a test database.
A script to create a table, populate it with data, and select data from the table:
ydb -p quickstart scripting yql -s '
CREATE TABLE series (series_id Uint64, title Utf8, series_info Utf8, release_date Date, PRIMARY KEY (series_id));
COMMIT;
UPSERT INTO series (series_id, title, series_info, release_date) values (1, "Title1", "Info1", Cast("2023-04-20" as Date));
COMMIT;
SELECT * from series;
'
Command output:
┌──────────────┬───────────┬─────────────┬──────────┐
| release_date | series_id | series_info | title |
├──────────────┼───────────┼─────────────┼──────────┤
| "2023-04-20" | 1 | "Info1" | "Title1" |
└──────────────┴───────────┴─────────────┴──────────┘
Running a script from the example above saved as the script1.yql
file, with results output in JSON
format:
ydb -p quickstart scripting yql -f script1.yql --format json-unicode
Command output:
{"release_date":"2023-04-20","series_id":1,"series_info":"Info1","title":"Title1"}
You can find examples of passing parameters to scripts in the article on how to pass parameters to YQL execution commands.