尝试在 sqlActivity 中使用脚本参数时:
{
"id" : "ActivityId_3zboU",
"schedule" : { "ref" : "DefaultSchedule" },
"scriptUri" : "s3://location_of_script/unload.sql",
"name" : "unload",
"runsOn" : { "ref" : "Ec2Instance" },
"scriptArgument" : [ "'s3://location_of_unload/#format(minusDays(@scheduledStartTime,1),'YYYY/MM/dd/hhmm/')}'", "'aws_access_key_id=????;aws_secret_access_key=*******'" ],
"type" : "SqlActivity",
"dependsOn" : { "ref" : "ActivityId_YY69k" },
"database" : { "ref" : "RedshiftCluster" }
}
其中 unload.sql 脚本包含:
unload ('
select *
from tbl1
')
to ?
credentials ?
delimiter ',' GZIP;
或者 :
unload ('
select *
from tbl1
')
to ?::VARCHAR(255)
credentials ?::VARCHAR(255)
delimiter ',' GZIP;
过程失败:
syntax error at or near "$1" Position
知道我做错了什么吗?
最佳答案
这是从 psql shell 运行良好的脚本:
insert into tempsdf select * from source where source.id = '123';
以下是我使用 Data-Pipelines 对 SqlActivity 进行的一些测试:
测试 1:使用 ? 的
insert into mytable select * from source where source.id = ?;
- 如果通过 SqlActivity 对象上的“script”和“scriptURI”选项使用,则工作正常。哪里
"ScriptArgument" : "123"
这里 ?可以替换条件的值,但不能替换条件本身。
测试 2:使用 参数 在仅使用 'script' 选项指定命令时有效
insert into #{myTable} select * from source where source.id = ?;
- 如果仅通过“脚本”选项使用,则工作正常insert into #{myTable} select * from source where source.id = #{myId};
如果仅通过“脚本”选项使用
其中
#{myTable}
, #{myId}
是其值可以在模板中声明的参数。http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-custom-templates.html
(when you are using only parameters, make sure you delete an unused scriptArguments - otherwise it will still throw and error)
失败的测试和推论:
插入 ? select * from source where source.id = ?;
插入 ? select * from source where source.id = '123';
以上两个命令都不起作用,因为
Table names cannot be used for placeholders for script arguments. '?''s can only be used to pass values for a comparison condition and column values.
insert into #{myTable} select * from source where source.id = #{myId}; - 如果用作“SciptURI”则不起作用
插入到 tempsdf select * from source where source.id = #{myId}; - 与“ScriptURI”一起使用时不起作用
以上 2 个命令不起作用,因为
Parameters cannot be evaluated if script is stored in S3.
插入到 tempsdf select * from source where source.id = $1 ; - 不适用于“scriptURI”
插入 tempsdf 值 ($1,$2,$3); - 不起作用。
using $'s - doesn't not work in any combination
其他测试:
“脚本参数”:“123”
“脚本参数”:“456”
“脚本参数”:“789”
insert into tempsdf values (?,?,?);
- 作为 scriptURI 、 script 并转换为 insert into tempsdf values ('123','456','789');
scriptArguments will follow the order you insert and replaces "?" in the script.
关于amazon-web-services - 亚马逊数据管道 : How to use a script argument in a SqlActivity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27481264/