保持列名从data.frame在输出表中的SQL服务器-2016

问题描述:

我有一个表中sql-server-2016保持列名从data.frame在输出表中的SQL服务器-2016

CREATE TABLE #tempData (A int not null) 
INSERT INTO #tempData VALUES (0); 
GO 

现在我可以调用具有表作为输入数据,我的R-脚本(包括列名):

EXECUTE sp_execute_external_script 
       @language = N'R' 
       , @script = N' 
         df <- InputDataSet 
         df$B <- 1L' 
       , @input_data_1 = N'SELECT * FROM #tempData' 
       , @output_data_1_name = N'df' 
WITH RESULT SETS (
    (A int not null, B int not null) 
); 

返回:

A B 
0 1 

预期。但是,我可以在不指定名称{A,B}的情况下执行相同操作,即直接使用data.frame中的名称。

不幸的是,如今BxlServer在SQL Server中如何转换R,您必须设置变量并在RESULTS SET中键入。

根据目前的文件(https://msdn.microsoft.com/en-us/library/mt604368.aspx),似乎不可能。

WITH RESULTS SETS clause is mandatory if you are returning a result set from R . The specified column data types need to match the types supported in R (bit, int, float, datetime, varchar) 
+0

谢谢你的回答。我确实读过这个,但在我看来这不一定是一样的。我知道set子句是强制性的,因为我需要指定类型,但是这不应该排除从'data.frame'中检索名称,或者? –