Re: [R] Question: RMySQL bulk load/update one column, dbWriteTable()?

2007-06-06 Thread Chris Stubben

 I have a question reading using RMySQL trying to load one R vector into a
 table column.  To be more specifically, the table is there populated.  Now I
 add a new column and want to populate this.
 


Okay, this is more of an SQL question now, but you could just use dbWriteTable
and then do an multi-table update.



dbGetQuery(con, select * from tmp)

  id name
1  1A
2  2B
3  3C
4  4D
5  5E


dbSendQuery(con, alter table tmp add column r2 float)

## calculate some statistic for all or some ids in table


x-dataframe(id=1:5, r2=c(.1, .4, .9, .4,.7))


dbWriteTable(con, r2tmp,  x )


dbSendQuery(con, update tmp t, r2tmp r set t.r2=r.r2 where t.id=r.id)


dbGetQuery(con, select * from tmp)

  id name  r2
1  1A 0.1
2  2B 0.4
3  3C 0.9
4  4D 0.4
5  5E 0.7


Chris

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Question: RMySQL bulk load/update one column, dbWriteTable()?

2007-06-06 Thread Waverley
Thanks Chris.  I am trying almost the same solution while I have failed the
dbWriteTable.

The problem of using update is that it is way TOO slow when the row size is
~20.

That is why I hope I can still get dbWriteTable way to add one column.
dbWriteTable is very efficient and fast.  The problem of dbWriteTable, so
far I know and so far I have read, is that you have to load one data frame
which covers all the columns of one table.  Now I want to do is bulky load
one column in stead of ALL columns.  Supposedly underneath dbWriteTable is
load data infile, which according to my reading should allow you to load
data infile to one table column.

can someone help?

Thanks.


On 6/6/07, Chris Stubben [EMAIL PROTECTED] wrote:


  I have a question reading using RMySQL trying to load one R vector into
 a
  table column.  To be more specifically, the table is there
 populated.  Now I
  add a new column and want to populate this.
 


 Okay, this is more of an SQL question now, but you could just use
 dbWriteTable
 and then do an multi-table update.



 dbGetQuery(con, select * from tmp)

 id name
 1  1A
 2  2B
 3  3C
 4  4D
 5  5E


 dbSendQuery(con, alter table tmp add column r2 float)

 ## calculate some statistic for all or some ids in table


 x-dataframe(id=1:5, r2=c(.1, .4, .9, .4,.7))


 dbWriteTable(con, r2tmp,  x )


 dbSendQuery(con, update tmp t, r2tmp r set t.r2=r.r2 where t.id=r.id)


 dbGetQuery(con, select * from tmp)

 id name  r2
 1  1A 0.1
 2  2B 0.4
 3  3C 0.9
 4  4D 0.4
 5  5E 0.7


 Chris

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Waverley @ Palo Alto

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.