Closed mdsumner closed 2 months ago
note that non-DB drivers will keep the geometry column whether it's in the query or not
GPKG drops 'geom' as it's not selected, but SHP keeps it, I don't have a strong opinion on this ...
gpkg %>%
filter(NAME %LIKE% 'A%') %>%
mutate(abc = 1.3) %>%
select(abc, NAME)
Thanks @mdsumner! This looks great. I'll give it a serious look in the next few days.
I went and made this PR into a package, so you can either use that or crib the DBI stuff from it when you're ready:
https://github.com/mdsumner/lazysf
If I get more into DBs I might come back and look at the more general case here, but rn I need this to get on with more general outputs from the lazy query.
SFSQL()
wraps the basic sql query toread_sf()
, passing in the DSN argument in the usual way (file, url, connection string) with a dummylayer
value.SFSQL_PG()
adds another level to allow input of host,dbname,user,password which is passed down as the 'PG:...' connection string toSFSQL()
.There is a lot I haven't considered, readonly is ignored, security/obfuscation on the connection string is ignored, and no detail on the difference between DB-drivers and non-DB:
i.e. DB drivers have the SQL passed in direct, so it is engine-specific, otherwise for non-DB afaik:
_ogr_geometry_
whether selected or not (see next comment)Discussed here: https://github.com/mdsumner/RGDALSQL/issues/7
Other:
Examples, first pseudocode for postgresql
Examples with SHP and GPKG