Skip to content

R and PostgreSQL - Writing data?

1 message · NISHIYAMA Tomoaki

#
Dear Kevin,
I do not understand why you need to leave the primary key unspecified.
You can change the field characteristics with ALTER TABLE, ALTER SEQUENCE,
and so on.  To see what operation is needed you can prepare a small
example table and use pg_dump.

"row.names" are copied by dbWriteTable
to ensure that every record is distinguishable.
It is by default a text field.
If you need a serial primary key, you may create a new column, and compute
the initial values and add constraints and index. 
(or just alter the column may work depending on the data.frame)

Note that pg_dump/restore should have been very well tested by 
PostgreSQL developers to ensure the reliability and the speed.
So, it would be a very hard to invent a better method.
What would be the calling convention of dbWriteTable, then?
Current one is very simple, that is,
dbWrtieTable(con, tablename, data.frame)

If you want to write the list of columns, then wouldn't 
it easier to make a data.frame that have only those columns?