英文:
Can you reference internal SQL files within a Synapse Workspace via another SQL file?
问题
可以在Synapse Workspace中使用另一个SQL文件通过存储过程引用和运行单独的SQL文件吗?我认为可以使用以下代码实现:
:r "MyFolder/MyQuery.sql"
有人知道是否仍然可能吗?
英文:
Is it possible to reference and run separate SQL files within your Synapse Workspace in your folder via another SQL file? Perhaps with the use of a stored procedure?
I thought it would be possible via this code:
:r "MyFolder/MyQuery.sql"
However Synapse does not recognise the ":r" sign and I am getting an error:
Does anyone know if it's still possible?
答案1
得分: 1
AFAIK,目前Synapse SQL不支持上述的:r
。您可以在此处提出功能请求。
您需要为此需求创建存储过程,并在另一个脚本文件中调用它。
如果您想要执行所有脚本文件,一种解决方法是将所有脚本复制到一个脚本文件中并执行它。
我使用了Powershell来完成这个操作。
使用Get-AzSynapseSqlScript
,首先我获取了所有脚本并将其存储在一个路径下。
$ok=Get-AzSynapseSqlScript -WorkspaceName rakeshsynapse
$queries=$ok.Properties.content.Query
$queries
Set-Content -path "scripts.sql" -Value $queries
现在,使用Set-AzSynapseSqlScript
,我已经将所有脚本复制到了一个新文件中。
$res_script = Get-AzSynapseSqlScript -WorkspaceName rakeshsynapse -Name <any_existing_script_name>
Set-AzSynapseSqlScript -SqlScript $res_script -DefinitionFile "scripts.sql"
Synapse中的文件:
但是,这种方法的限制在于,仅当您需要执行所有文件时才能在不进行太多手动操作的情况下工作。如果您只需要执行其中一些文件,那么也需要手动输入这些文件的名称。因此,在这种情况下最好使用存储过程。
英文:
AFAIK, currently, the above :r
is not supported in Synapse SQL. You can raise a feature request for that here.
You need to create stored procedure for this requirement and call it in another script file.
If you want to execute all script files, one workaround is copying all the scripts into a script file and execute it.
I have used Powershell for it.
Using Get-AzSynapseSqlScript
, first I got all the scripts and store those by using a path.
$ok=Get-AzSynapseSqlScript -WorkspaceName rakeshsynapse
$queries=$ok.Properties.content.Query
$queries
Set-Content -path "scripts.sql" -Value $queries
Now, using Set-AzSynapseSqlScript
I have copied all scripts to a new file.
$res_script = Get-AzSynapseSqlScript -WorkspaceName rakeshsynapse -Name <any_existing_script_name>
Set-AzSynapseSqlScript -SqlScript $res_script -DefinitionFile "scripts.sql"
File in Synapse:
But, this approach has a limitation that it will work without much manual work only when you have the requirement to execute all the files. If you need to execute only some of the files, it will also involves manual work like giving the file names of those. So, better to use Stored procedures in that case.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论