arguments - 如何在 CQL 命令中包含输入参数 - 源

标签 arguments cassandra cql

在 Cassandra 查询语言 (CQL) 中,有一个名为 source 的便捷命令,它允许用户执行存储在外部文件中的 cql 命令。

SOURCE

Executes a file containing CQL statements. Gives the output for each
statement in turn, if any, or any errors that occur along the way.

Errors do NOT abort execution of the CQL source file.

Usage:
      SOURCE '<file>';

但我想知道是否可以允许这个外部文件接受额外的输入参数。 例如,假设我想开发以下带有两个输入参数的 cql 文件:

create keyspace $1 with
    strategy_class='SimpleStrategy' and
    strategy_options:replication_factor=$2;

并且想通过以下方式在 cqlsh 中执行此 cql:

source 'cql-filename' hello_world 3

我开发了上面的示例 cql,将其存储在名为 create-keyspace.cql 的文件中,并尝试了一些我能想到的可能命令,但它们都不起作用。

cqlsh> source 'create-keyspace.cql'
create-keyspace.cql:2:Invalid syntax at char 17
create-keyspace.cql:2:  create keyspace $1 with strategy_class='SimpleStrategy' and strategy_options:replication_factor=$2;
create-keyspace.cql:2:                  ^
cqlsh> source 'create-keyspace.cql' hello_world 3
Improper source command.
cqlsh> source 'create-keyspace.cql hello_world 3'
Could not open 'create-keyspace.cql hello_world 3': [Errno 2] No such file or directory: 'create-keyspace.cql hello_world 3'

我可以知道CQl是否有这种类型的支撑吗?如果是,那么我应该如何正确执行?

最佳答案

cqlsh 并不是真正想要成为一个脚本环境。听起来使用 Python CQL 驱动程序会更好:https://github.com/datastax/python-driver

关于arguments - 如何在 CQL 命令中包含输入参数 - 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18136807/

相关文章:

bash - 如何拦截和删除 bash 中的命令行参数

intellij-idea - IntelliJ 将参数与左括号对齐?

function - PowerShell 中 $args 的混淆评估

cassandra - 墓碑与节点工具和修复

cassandra - 我可以在cassandra中的多个列上创建二级索引吗

python-2.7 - Cassandra 3.1 Python驱动程序“输入描述中没有可行的替代方法”

batch-file - 读取批处理文件中参数的每个字符

Cassandra CQL : counter column creation and modification

select - 是否可以在 select 语句 Cassandra 中的 where 子句之后传递任何其他列

cassandra - CQL3 中一组列的 TTL 字段 - Cassandra