I searched around and found similar questions (Writing Non Spatial Table into Geopackage - Python), but that discussion is on a slightly different topic.
Is there a way to write attribute-only tables into a Geopackage using GeoPandas?
You need to specify a geometry field to create a GeoDataFrame. This is the error you get if there isn't one:
Import geopandas as gpd sql = "select * from attronly" con = ###your connection### gdf = gpd.read_postgis(sql, con)
ValueError: Query missing geometry column 'geom'
But you can create an empty geom field and then drop it afterwards. If you do that, however, there's a different error as the function still expects there to be geometries to parse:
Import geopandas as gpd sql = "select null as geom,* from attronly" con = ###your connection### gdf = gpd.read_postgis(sql, con) gdf.drop(columns=['geom'],inplace=True) gdf.to_file("file.gpkg", layer='attronly', driver="GPKG")
AttributeError: No geometry data set yet (expected in column 'geom'.)
I suspect the solution is either using Pandas to write into a Geopackage (though I can't find any documentation about that), or going back and using Fiona directly. I can also write in that nulled geometry field and then remove it afterwards from the Geopackage, but I'm hoping for some expert advice on doing this without bandaid solutions.