简体   繁体   English

R Shiny应用程序中的SQL查询语法-CAST

[英]SQL query syntax in R shiny app - CAST

This is a follow up to this question: Working with reactiveValues and ggplot in shiny . 这是此问题的后续解决方案: 使用Shiny中的reactValues和ggplot I am making a shiny app that queries an SQL database. 我正在制作一个查询SQL数据库的闪亮应用程序。 In my working example for the question, I managed to avoid changing the format of reactive data within shiny by using CAST to automatically import data with a specific format: 在这个问题的工作示例中,我设法避免了通过使用CAST自动导入具有特定格式的数据来更改Shiny中反应性数据的格式:

Query without cast 查询无演员表

b <- reactive({ paste("select Wafer, Batch, MeasurementA, MeasurementB from dd where ID=",e()," Order by  ID asc ;", sep="") })

Query with cast to automatically change column format 使用强制转换查询以自动更改列格式

b <- reactive({ paste("select cast(Wafer as varchar) as Wafer, cast(Batch as varchar) as Batch, MeasurementA, MeasurementB from dd where ID=",e()," Order by  ID asc ;", sep="") })

This worked fine in the working example I used for my question. 在我用于我的问题的工作示例中,这工作得很好。 However, when I came to apply this to my real app I get a syntax error: 但是,当我将其应用于我的真实应用程序时,出现语法错误:

b <- reactive({ paste("select cast(e.erf_num as varchar) as ERF, cast(w.wafer_id as varchar) as Wafer, d.name,d.row,d.col,d.width,d.length,t.test_date, 

                        t.von_fwd,t.vth_fwd,t.sts_fwd,t.on_off_fwd,t.curr_on_fwd,t.curr_off_fwd,t.rds_on_fwd, t.rds_on_fwd,
                        t.von_rev,t.vth_rev,t.sts_rev,t.on_off_rev,t.curr_on_rev,t.curr_off_rev,t.rds_on_rev, t.rds_on_rev, t.delta_vth, t.id

                        from transfer_data_temp AS t
                        inner join wafer AS w ON t.wafer_id=w.id
                        inner join device AS d ON t.device_id=d.id
                        inner join erf AS e on t.wafer_id=e.wafer_id

                        where
                        t.wafer_id=",e()," Order by  d.name asc , t.test_date;", sep="") })


Unhandled error in observer: could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'varchar), cast(wafer.wafer_id as varchar), d.name,d.row,d.col,d.width,d.length,t' at line 1 

I know the query works without the CAST because ive used it successfully before. 我知道查询无需CAST就可以使用,因为ive以前已经成功使用过它。 So I draw attention to this part of the query: 因此,我提请注意查询的这一部分:

  b <- reactive({ paste("select cast(e.erf_num as varchar) as ERF, cast(w.wafer_id as varchar) as Wafer, 

Any ideas why this works in the former but not the latter? 任何想法为什么这在前者中有效但在后者中无效? I can post all my code to give a full working example if it helps (avoided ATM because its a tad long). 如果有帮助,我可以发布所有代码以给出完整的工作示例(避免使用ATM,因为它有点长)。 Thanks. 谢谢。 Pete 皮特

ah ok, for some reason if I change AS varchar to AS character it works. 嗯,由于某种原因,如果我将AS varchar更改为AS character则可以使用。 Dont no why. 不,为什么。 I should have played around a bit more before asking the question! 在问这个问题之前,我应该多玩一些!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM