pramsey / pgsql-ogr-fdw

PostgreSQL foreign data wrapper for OGR
MIT License
237 stars 34 forks source link

Import foreign schema should use exact schema name #173

Closed Ellebjerg closed 4 years ago

Ellebjerg commented 4 years ago

I am using ogr_fdw to access wfs datasources. When I run

IMPORT FOREIGN SCHEMA "pdk:theme_pdk_lokalplan_vedtaget_v",

I get 2 tables, pdk_theme_pdk_lokalplan_vedtaget_v and pdk_theme_pdk_lokalplan_vedtaget_vindmoelle_v.

It would be nice if the import function only looks for the exact schema name.

Besides this little hickup, thanks for a well functioning and fairly easy to use extension!

pramsey commented 4 years ago

I'm afraid this is kind of by design... the idea is that OGR layer names are just big long strings. Sometimes they have schemas prepended. Sometimes they don't (like in a directory of shape files). By treating the "schema" as a simple text prefix, it makes it possible for users to import a subcollection of similarly named files (fooshp1, fooshp2, fooshp3) even from data sources that don't "understand" the idea of a schema. We could start looking for magic "schema separator" characters (".", ":") but that would change behaviour. Question for @robe2 is if that change is such a big deal. It's not clear that the behaviour as designed actually gets much exercise.

robe2 commented 4 years ago

I personally use the schema prefix quite a bit as a wildcard and though I had started using it mostly for databases that supported schemas to bring in a specific schema of tables, I find I end up using it a lot more for other things because people tend to prefix their common themed tables with same prefix much more than they use schemas.

In the above example he could use the LIMIT TO to reduce to the tables he wants. That's what I do in these situations.

That makes more sense to me. So something like:

IMPORT FOREIGN SCHEMA "pdk:theme_pdk_lokalplan_vedtaget_v" LIMIT TO (pdk_theme_pdk_lokalplan_vedtaget_v); 

I think your proposal of schema separators would break his use, cause isn't "pdk:" the schema in WFS talk? So he's actually looking for a specific table, not a schema of tables.