[R-sig-DB] RODBC sqlSave to table with computed column.

Mortensen, Mikael - Marketing M|k@e|@Morten@en @end|ng |rom p@e@com
Tue May 29 21:16:20 CEST 2012


Hello. I would like to append records to a sql server table with a computed column. The computed column is the product of two other columns in the same table. In my first attempt I used a dataframe with all of the columns populated less the computed column, but I received and error

Submitted:
sqlSave(riskDB, optHedgesFiltered, tablename = "OptHedges", append = TRUE, verbose=TRUE, rownames=FALSE)

ERROR:
Query: INSERT INTO "OptHedges" ( "Book", "DealTicket", "TransactionDate", "ForwardDate", "Location", "DemandProfile", "Volume", "Price", "Contract" ) VALUES ( ?,?,?,?,?,?,?,? )
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test,  : 
  missing columns in 'data'


If I change the dataframe to include contract (the computed column) the ERROR changes to:

sqlwrite returned 
[RODBC] Failed exec in Update
42000 271 [Microsoft][ODBC SQL Server Driver][SQL Server]The column "Contract" cannot be modified because it is either a computed column or is the result of a UNION operator.

Am I missing something in the sqlSave to deal with the computed column? As a test to make sure that I could append at all, I created a copy of the table I am trying to append to on the server and removed the computed column. The sqlSave statement above worked perfectly on the copy without the computed column.

Any direction is appreciated.

Thanks,
Mikael




More information about the R-sig-DB mailing list