Save column names from data.frame in 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 table as input (including 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)
);

Return:

A   B
0   1

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

+4
source share
2 answers

Unfortunately, when BxlServer translates R into SQL Server today, you have to set the variable and enter RESULTS SET.

0
source

(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

Source: https://habr.com/ru/post/1622089/


All Articles