将RPostgres或RPostgreSQL dbGetQuery()参数传递给IN运算符

时间:2018-12-04 15:40:34

标签: r postgresql

只是想知道是否有办法通过queue: name: Hosted VS2017 demands: npm steps: - task: NodeTool@0 displayName: 'Use Node 8.x' inputs: versionSpec: 8.x - task: Npm@1 displayName: 'npm install angular cli' inputs: command: custom verbose: false customCommand: 'install @angular/cli -g' - task: Npm@1 displayName: 'npm install packages' inputs: verbose: false - script: 'npm run build:ssr' displayName: 'build the project' - task: CopyFiles@2 displayName: 'Copy dist files to staging' inputs: SourceFolder: '$(Build.SourcesDirectory)/dist' TargetFolder: '$(Build.ArtifactStagingDirectory)/app/dist' - task: CopyFiles@2 displayName: 'Copy server.js to the root' inputs: SourceFolder: '$(Build.ArtifactStagingDirectory)/app/dist' Contents: server.js TargetFolder: '$(Build.ArtifactStagingDirectory)/app' - task: DeleteFiles@1 displayName: 'Delete the dist/server.js' inputs: SourceFolder: '$(Build.ArtifactStagingDirectory)/app/dist' Contents: server.js - task: AzureRmWebAppDeployment@3 displayName: 'Azure App Service Deploy: website' inputs: azureSubscription: 'Subscription 1' WebAppName: website DeployToSlotFlag: true ResourceGroupName: Temp SlotName: master Package: '$(Build.ArtifactStagingDirectory)/app' GenerateWebConfig: true WebConfigParameters: '-Handler iisnode -NodeStartFile server.js -appType node' UseWebDeploy: true RemoveAdditionalFilesFlag: true 的{​​{1}}将任意数量的参数传递给IN子句

例如,给定其中一个

params

我能做些什么吗?

dbGetQuery()

其中标识符是“值的简短列表”,即通常少于10个整数或字符串。我以为我可以做类似的事情:

dbcon <- dbConnect(RPostgres::Postgres())
# or: dbcon <- dbConnect(RPostgreSQL::PostgreSQL())

dbExecute(dbcon, "CREATE TEMP TABLE foo AS SELECT i FROM generate_series(1, 10) x(i);")

但是我能做的最好的是:

dbGetQuery(dbcon, "SELECT * FROM foo WHERE i IN (1, 2, 3)")

但是从一组字符串中生成ids <- c(1, 2, 3) dbGetQuery(dbcon, "SELECT * FROM foo WHERE i IN $1", list(ids)) 有点容易出错。

1 个答案:

答案 0 :(得分:1)

您要使用function filterByClasses(elements, classes) { return Array.from(elements).filter(elem => { return !classes.map(elem.classList.contains).includes(false); } } // Usage: let filtered = filterByClasses( document.getElementById('#element').children, ['two', 'three'] ); 来生成动态查询。这比不安全地将查询粘贴在一起更好。但是,它对于矢量输入来说效果不佳,因此,DBI::sqlInterpolate可以很好地工作,如果您可以忍受更多的包导入。示例:

dbplyr::translate_sql