这是在 psql shell 中运行良好的脚本:
insert into tempsdf select * from source where source.id = '123';
这是我的一些测试sql活动使用数据管道:
Test 1: 使用?'s
insert into mytable select * from source where source.id = ?;
- 如果通过 SqlActivity 对象上的“script”和“scriptURI”选项使用,则工作正常。
where "ScriptArgument" : "123"
这里 ?可以替换条件的值,但不能替换条件本身。
Test 2 : Using 参数仅当使用“脚本”选项指定命令时才有效
insert into #{myTable} select * from source where source.id = ?;
- 如果仅通过“脚本”选项使用则工作正常
insert into #{myTable} select * from source where source.id = #{myId};
where #{myTable}
, #{myId}
是可以在模板中声明其值的参数。
http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-custom-templates.html
(当您仅使用参数时,请确保删除未使用的
scriptArguments - 否则它仍然会抛出错误)
失败的测试和推论:
插入 ?从源中选择 *,其中 source.id = ?;
插入 ?从源中选择 *,其中 source.id = '123';
上面的两个命令都不起作用,因为
表名称不能用作脚本参数的占位符。 '?' 只能用于传递比较条件和列值的值。
插入#{myTable} select * from source where source.id = #{myId}; - 如果用作“SciptURI”则不起作用
插入到 tempsdf select * from source where source.id = #{myId}; - 与“ScriptURI”一起使用时不起作用
上面 2 个命令不起作用,因为
如果脚本存储在 S3 中,则无法评估参数。
插入到 tempsdf select * from source where source.id = $1 ; - 不适用于“scriptURI”
插入 tempsdf 值 ($1,$2,$3); - 不起作用。
使用 $'s - 在任何组合中都不起作用
其他测试:
“脚本参数”:“123”
“脚本参数”:“456”
“脚本参数”:“789”
insert into tempsdf values (?,?,?);
- 既可用作 scriptURI ,也可用作 script 并转换为insert into tempsdf values ('123','456','789');
scriptArguments 将遵循您插入的顺序并替换“?”在
剧本。