Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write this json object in Postgresql with R

I have this table

CREATE TABLE example (
ID serial NOT NULL PRIMARY KEY,
    name varchar(1024),
    coords json
);

And I want to write this json in this table:

[
    {
            "name": "first",
        "coords":{
            "lat": 3.14,
            "lon": 2.5
        }
    }
]

I am trying with jsonlite and Rpostgresql, but error

like image 387
Francisco Palomares Avatar asked Mar 25 '26 20:03

Francisco Palomares


1 Answers

I have and application where I have JSON data and uploading it to postgres as it. In that case, I am converting JSON to character and writing it to database.

upload =  data.frame(name = name, coords = c(JSONCoords))
dbWriteTable(con, c("table"), value=upload, append=TRUE, row.names=FALSE)
like image 94
Not_Dave Avatar answered Mar 27 '26 11:03

Not_Dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!