Reputation: 33
I don't understand the st_read
function from the sf
package.
I try to follow the example given in the help with my own postgisdata.
**Connection to postgis:**
connz <- dbConnect(PostgreSQL(), dbname="gisdb", user = "postgres", password="postgres", host = "127.0.0.1")
**check tables in connection**
dbListTables(connz)
**Response**
*...
[41] "mijnlocatiesgoogle20171127" "vakantie"
[43] "vakantieactiviteiten" "uitmetbram"
...
So there is a connection
**Get data using st_read**
xx = st_read(connz, "vakantie", query = "SELECT * FROM vakantie LIMIT 3;")
***Response**
xx = st_read(connz, "vakantie", query = "SELECT * FROM vakantie LIMIT 3;")
Warning message: In st_read.DBIObject(...) : Ignoring query argument, only using table*
Question: Why is the query argument ignored and how do i get it to work,
Upvotes: 2
Views: 1096
Reputation: 1000
Just remove the table argument.
xx = st_read(connz, query = "SELECT * FROM vakantie LIMIT 3;")
I've also had better luck with the RPostgres::Postgres()
driver instead of the PostgreSQL()
one. You should also specify the port when defining your connection object.
connz <- dbConnect(drv = RPostgres::Postgres(), dbname="gisdb", user = "postgres", password="postgres", host = "127.0.0.1")
Upvotes: 0
Reputation: 278
The query argument is ignored because by specifying the table sf assumes you want to bring in the table whole. Just run with the query because you already specify the table within that query. The table option there is redundant and the default behavior will try to read the whole table in as a result.
Upvotes: 3