6

I have a table in sql-server-2016:

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

Now I can call my R-script having the table as the input data (incl. column names):

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)
);

Returning:

A   B
0   1

as expected. But can I do the same without specifying the names, {A,B}, i.e. it will use the names from the data.frame directly.

J.R.
  • 3,838
  • 1
  • 21
  • 25

2 Answers2

1

Unfortunately with how BxlServer translates R in SQL Server today, you have to set the variable and type in RESULTS SET.

ShauMS
  • 71
  • 1
0

According to the current documentation (https://msdn.microsoft.com/en-us/library/mt604368.aspx) it seems not possible.

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)
Ivan Popivanov
  • 169
  • 2
  • 7
  • Thank you for the answer. I did read this, but this is not necessarily the same in my opinion. I know the set clause is mandatory because I need to specify the types, but this shouldn't exclude retrieving the names from the `data.frame`, or? – J.R. Dec 30 '15 at 08:26