在R中执行SQL脚本时如何使用动态值 [英] How to use dynamic values while executing SQL scripts in R

查看:150
本文介绍了在R中执行SQL脚本时如何使用动态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的R工作流程现在涉及处理许多查询(RPostgreSQL库).我真的很想使代码在将来易于维护和管理.

My R workflow now involves dealing with a lot of queries (RPostgreSQL library). I really want to make code easy to maintain and manage in the future.

我开始从单独的.SQL文件中加载大型查询(帮助),效果很好.

I started loading large queries from separate .SQL files (this helped) and it worked great.

然后我开始使用插值(

Then I started using interpolated values (that helped) which means that I can write

SELECT * FROM table WHERE value = ?my_value;

并且(在将其加载到R中之后)使用sqlInterpolate(ANSI(), query, value = "stackoverflow")对其进行插值.

and (after loading it into R) interpolate it using sqlInterpolate(ANSI(), query, value = "stackoverflow").

现在发生的事情是我想使用这样的东西

What happens now is I want to use something like this

SELECT count(*) FROM ?my_table;

但是我如何使它工作呢? sqlInterpolate()默认情况下仅安全插值.有解决方法吗?

but how can I make it work? sqlInterpolate() only interpolates safely by default. Is there a workaround?

谢谢

推荐答案

sqlInterpolate()仅用于替换值,不适用于表名称之类的其他组件.您可以使用其他模板框架,例如 brew 晶须.

sqlInterpolate() is for substituting values only, not other components like table names. You could use other templating frameworks such as brew or whisker.

这篇关于在R中执行SQL脚本时如何使用动态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆