Cidree / rpostgis

rpostgis: R Interface to a 'PostGIS' Database
http://cidree.github.io/rpostgis/
77 stars 14 forks source link

pgWriteGeom() fails when writing a data frame with a timestamp column #32

Closed polymathematic closed 7 months ago

polymathematic commented 7 months ago

When attempting to write a data frame that contains a timestamp with the pgWriteGeom() function, the function throws an error when it attempts to write the .R_df_defs table.

Creating new table...
New R data frame definitions table created ("owm".".R_df_defs").
Error in pgWriteGeom(conn, c("owm", "test1234"), df, df.mode = FALSE) : 
  Table preparation failed. No changes made to database.

It should be noted that this occurs even when the user tries to set df.mode to FALSE as pgWriteGeom() seems to have this hardcoded as TRUE for data frames.

Example:

library(rpostgis)

df <- data.frame(dt = Sys.time(),
           x = 1:3,
           y = letters[1:3])

pgWriteGeom(conn, "test_table"), df, df.mode = FALSE)

Ubuntu 20.04.6 LTS, R version 4.3.1, rpostgis_1.5.1

Thanks!

Cidree commented 7 months ago

Hello @polymathematic. Sorry for the delay, these are hard days.

I found a bug in the code, because the datetime column have two classes, and it was causing an error when retrieving the object class.

I just fixed the error, and it should be working properly in the GitHub version. Let me know if you can solve the issue with the GitHub version.

Best, Cidre

polymathematic commented 7 months ago

Thank you so much, @Cidree. I really appreciate you maintaining rpostgis.