Good evening to all!
The problem is as follows:
Clause 1 I use the RODBC package. The use of the sqlSave function for inserting a table into the database was unsuccessful, because "table not found in channel" channel and did not upload anything there).
2, so I resorted to cycles: I create an empty table in the database myself and fill it in line by line using the insert value (code below) the entire table. All anything, if not speed. This method works for me at a speed of 150 lines per minute. I need to fill in 3 million lines.
In this regard, two questions:
- How to fix tbale not found in channel error in claim 1?
- Are there any ways to increase the speed to normal in step 2.? Why so slow and how to fix it?
Maybe there is an alternative to these two methods? Proven and working.
conn <- odbcDriverConnect(connection ="Driver={SQL Server};Server=servername.com; catalog=Analysis;Uid=login;Pwd=parole")
sqlQuery (conn, paste ("use Analysis;", "if object_id ('Analysis.dbo.ChM_credit_cards') is not null", "drop table dbo.ChM_credit_cards"))
sqlQuery(conn, paste ("use Analysis; ", "create table Analysis.dbo.ChM_credit_cards (", "id int null, ", "external_id nvarchar(100) null, ", "card_name nvarchar(50) null, ", "user_id bigint null, ", "expiry_status nvarchar(20) null, ", "is_deleted smallint null, ", "expiry_date date null, ", "card_number nvarchar(50) null, ", "is_business smallint null, ", "created_at datetime null, ", "updated_at datetime null, ", "saved_email nvarchar(100) null, ", "holder_name nvarchar(100) null, ", "activated smallint null, ", "identifier_id bigint null)")) nr <- nrow(crcard) for (i in 1:nr) { id_crc <- crcard$id[i] external_id_crc <- crcard$external_id[i] card_name_crc <- crcard$name[i] user_id_crc <- crcard$user_id[i] expiry_status_crc <- crcard$expiry_status[i] is_deleted_crc <- crcard$is_deleted[i] expiry_date_crc <- as.character(crcard$expiry_date[i]) card_number_crc <- crcard$number[i] is_business_crc <- crcard$is_business[i] created_at_crc <- as.character(crcard$created_at[i]) updated_at_crc <- as.character(crcard$updated_at[i]) email_crc <- crcard$saved_email[i] holdername_crc <- crcard$holder_name[i] activated_crc <- crcard$activated[i] identifier_id_crc <- ifelse(is.na(crcard$identifier_id[i])==TRUE, 0, crcard$identifier_id[i]) sqlQuery(conn, paste ("use Analysis; ", "insert into Analysis.dbo.ChM_credit_cards ", "(id , external_id, card_name, ", "user_id, expiry_status, is_deleted, ", "expiry_date, card_number, is_business, ", "created_at, updated_at, saved_email, ", "holder_name, activated, identifier_id)", "values (", id_crc,", '", external_id_crc,"', '", card_name_crc, "', ", user_id_crc, ", '", expiry_status_crc, "', ", is_deleted_crc, ", '", expiry_date_crc, "', '", card_number_crc, "', ", is_business_crc, ", '", created_at_crc,"', '", updated_at_crc,"', '", email_crc, "', '", holdername_crc, "', ", activated_crc, ", ", identifier_id_crc, ")")) }
insertseveral values โโof inserted rowsinsert into tableName (id, field1, field2) values (1, 'x1', 'y1'), (2, 'x2', 'y2'), ....limiting the size of the generated query to reasonable limits. - terandeleteandtruncate, the latter is done quickly and without writing logs. Checks integrity constraints like you do not. - teran