mar*_*nun 8 amazon-s3 amazon-web-services amazon-redshift amazon-data-pipeline
尝试在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" }
}
Run Code Online (Sandbox Code Playgroud)
其中unload.sql脚本包含:
unload ('
select *
from tbl1
')
to ?
credentials ?
delimiter ',' GZIP;
Run Code Online (Sandbox Code Playgroud)
要么 :
unload ('
select *
from tbl1
')
to ?::VARCHAR(255)
credentials ?::VARCHAR(255)
delimiter ',' GZIP;
Run Code Online (Sandbox Code Playgroud)
进程失败:
syntax error at or near "$1" Position
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?
这是从 psql shell 运行良好的脚本:
insert into tempsdf select * from source where source.id = '123';
Run Code Online (Sandbox Code Playgroud)
以下是我使用 Data-Pipelines对SqlActivity进行的一些测试:
测试 1:使用? 的
insert into mytable select * from source where source.id = ?; - 如果通过 SqlActivity 对象上的 'script' 和 'scriptURI' 选项使用,则工作正常。
在哪里 "ScriptArgument" : "123"
这里 ?可以替换条件的值,但不能替换条件本身。
测试 2:仅在使用“脚本”选项指定命令时使用参数有效
insert into #{myTable} select * from source where source.id = ?; - 如果仅通过“脚本”选项使用,则工作正常
insert into #{myTable} select * from source where source.id = #{myId};
Run Code Online (Sandbox Code Playgroud)
其中#{myTable}, #{myId}是可以在模板中声明其值的参数。
http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-custom-templates.html
(当您仅使用参数时,请确保删除未使用的 scriptArguments - 否则它仍然会抛出并出错)
失败的测试和推论:
插入 ?select * from source where source.id = ?;
插入 ?select * from source where source.id = '123';
以上两个命令都不起作用,因为
表名不能用作脚本参数的占位符。“?”只能用于传递比较条件和列值的值。
insert into #{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 - 不能以任何组合使用
其他测试:
“ScriptArgument”:“123” “ScriptArgument”:“456” “ScriptArgument”:“789”
insert into tempsdf values (?,?,?); - 作为 scriptURI 、 script 和转换为 insert into tempsdf values ('123','456','789');
scriptArguments 将按照您插入的顺序并替换“?” 在脚本中。
我相信您正在将此 sql 活动用于 Redshift。您可以修改您的 sql 脚本以使用位置符号来引用参数吗?要引用 sql 语句本身中的参数,请使用 $1、$2 等。
请参阅http://www.postgresql.org/docs/9.1/static/sql-prepare.html
| 归档时间: |
|
| 查看次数: |
5633 次 |
| 最近记录: |