Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying information_schema.tables.is_insertable_into with vsizip datasource errors #221

Open
robe2 opened this issue Sep 29, 2021 · 2 comments

Comments

@robe2
Copy link
Contributor

robe2 commented Sep 29, 2021

CREATE EXTENSION ogr_fdw;
CREATE SCHEMA staging;
DROP SERVER IF EXISTS fds_ne CASCADE;
CREATE SERVER fds_ne 
    FOREIGN DATA WRAPPER ogr_fdw
    OPTIONS(datasource '/vsizip//vsicurl/http://postgis.us/downloads/ne_10m_admin_1_states_provinces.zip', format 'ESRI Shapefile');

IMPORT FOREIGN SCHEMA ogr_all FROM SERVER fds_ne INTO staging; 

I also tried with: datasources which are equivalent: /fdw_data/argentina-latest-free.shp.zip and /vsizip//fdw_data/argentina-latest-free.shp.zip. Both work as far as linking and querying but the one with /vsizip chokes in the information_schema.tables query

CREATE SERVER fds_ne 
    FOREIGN DATA WRAPPER ogr_fdw
    OPTIONS(datasource '/vsizip//http://postgis.us/downloads/ne_10m_admin_1_states_provinces.zip', format 'ESRI Shapefile');

Works fine outputs:

NOTICE:  Number of tables to be created 1
IMPORT FOREIGN SCHEMA

This also works:

SELECT f_table_name, f_geometry_column, coord_dimension, srid, type 
FROM geometry_columns 
WHERE f_table_schema = 'staging';

This gives error, but leaving out the is_insertable_into column, it works okay

SELECT table_name, table_type, is_insertable_into 
FROM information_schema.tables 
WHERE table_schema = 'staging';

Error:

ERROR:  GDAL OpenFailed [4] Unable to open /vsizip//vsicurl/http://postgis.us/downloads/ne_10m_admin_1_states_provinces.zip/ne_10m_admin_1_states_provinces.shp or /vsizip//vsicurl/http://postgis.us/downloads/ne_10m_admin_1_states_provinces.zip/ne_10m_admin_1_states_provinces.SHP.
SQL state: XX000

Expected behavior is the query does not error and the is_insertable_into has a false in output because vszip are not editable.

My Version info

SELECT ogr_fdw_version();

outputs:

OGR_FDW="1.1" GDAL="3.2.0"
@pramsey
Copy link
Owner

pramsey commented Sep 29, 2021

Minimal reproduction:

select pg_relation_is_updatable('staging.ne_10m_admin_1_states_provinces'::regclass,false);

@pramsey
Copy link
Owner

pramsey commented Sep 29, 2021

OK, I'm pretty sure I see what's happening, but not sure how to fix it without an axe. The updateable test is trying a "soft updateable open" on the file to see if its openable, but the GDAL open process is tossing a CE_FATAL error when it cannot open one of the shp components in updateable mode. That in turn gets mapped in the OGR error handler to a PgSQL FATAL which stops everything dead, so the logic further on, that checks for a NULL layer and sets the updateable to False never gets to run.

It may be that the soft update check logic just never worked at all, and never had a chance to be tested. I should try opening a local shp file that has only read bits set.

Workaround would be to declare the layer not updateable in the layer options, since that check gets done before the opening test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants