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

时间:2015-08-11 04:34:24

标签: mysql sql r shiny

这是对此问题的跟进:Working with reactiveValues and ggplot in shiny。我正在制作一个查询SQL数据库的闪亮应用程序。在我的问题的工作示例中,我设法避免使用CAST自动导入具有特定格式的数据来更改闪亮内的活动数据格式:

不投出

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

使用强制转换查询以自动更改列格式

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="") })

这在我用于我的问题的工作示例中运行良好。但是,当我将其应用于我的真实应用程序时,我收到语法错误:

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 

我知道查询在没有CAST的情况下有效,因为我之前成功使用过它。所以我提请注意这部分查询:

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

为什么这种方法适用于前者而不适用于后者?如果有帮助的话,我可以发布我的所有代码,以提供一个完整的工作示例(避免ATM,因为它有点长)。谢谢。皮特

1 个答案:

答案 0 :(得分:0)

啊,好吧,出于某种原因,如果我将AS varchar更改为AS character则可行。不,为什么。在问这个问题之前我应该​​多玩一点!