0

I have a table i wish to insert records into in a Teradata environment using R I have connected to the the DB and created my Table using JDBC From reading the documentation there doesn't appear to be an easy way to insert records into the system except to create your own manual insert statements. I am trying to do this by creating a vectorized approach using apply (or anything similar)

Below is my code but I'm clearly not using apply correctly. Can anyone help?

s <- seq(1:1000)
str_update_table <- sprintf("INSERT INTO foo VALUES (%s)", s) 

# Set Up the Connections
myconn <- dbConnect(drv,service, username, password)

# Attempt to run each of the 1000 sql statements
apply(str_update_table,2,dbSendUpdate,myconn)

1 Answer 1

1

I have not got the infrastructure to test, but you pass a vector to apply where apply expects an array. With your vector str_update_table the 2 in apply does not make much sense.

Try Map like in

Map(function(x) dbSendUpdate(myconn, x), str_update_table)

(untested)

Sign up to request clarification or add additional context in comments.

2 Comments

Hi @Bernhard. i was hoping we could use purrr for this so thank for for suggesting it. It works perfectly. Sorry i had a typo originally
I am not familiar with purrr but simple tasks like this usually work well without additional packages. Glad, it worked for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.