Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep column names from a data.frame in an output table in sql-server-2016

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.

like image 549
J.R. Avatar asked Nov 20 '22 19:11

J.R.


1 Answers

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

like image 112
ShauMS Avatar answered Nov 23 '22 09:11

ShauMS