I have just read that the =>
operator for the hstore extension is deprecated and might be removed in future versions. This is bad news to because I have several functions in R that
rely on using this operator when storing to Postgres table that contains hstore fields.
I prepare a data.frame
or data.table
in memory (R Session) before I write to the database.
Subsequently I just write the entire table in memory to the database by using the convenient function dbWriteTable
. Hence it would be inconvenient to use the postgres function hstore(text,text).
What is a good strategy to handle such an announcement? I am quite surprised they are removing the operator since there must be quite some people writing to hstore alongside fields of other types. Also this is not really R-specific. It has to be the same issue for many languages..
Though I got some helpful insights so far, maybe this helps to clarify what my problem is:
I added a reproducible example for the R folks and a screenshot for the rest of the world..
I build a data.frame in R (basically a table representation in memory) like this:
mydf <- structure(list(ts_key = c("somekey",
"somekey"), ts_language = c("de", "en"
), ts_labels = c("\"Kurztitel\" => \"Wohlbefinden\",\"mögliche_Antworten\" => \"fantastisch,so lala,total fertig\",\"Wortlaut\" => \"Wie geht es?\"",
"\"available_items\" => \"awesome,somewhat ok,wasted\",\"short_title\" => \"well being\",\"wording\" => \"How are you?\""
)), .Names = c("ts_key", "ts_language", "ts_labels"), row.names = c(NA,
-2L), class = "data.frame")
So the memory table / data.frame contains an hstore
as a character as one of its columns.
This is very convenient because I can have a data.frame with lots of rows and then simply use:
dbWriteTable(myconnection,"somePostgresTableWithTheRightStructure",mydf,append=T)
and just write the entire data.frame to the db without having to build the query or explicit looping. I'd love to keep this but I just don't know how tell dbWriteTable
to use hstore(text,text).