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

Invalid search path when listing tables from hosted Postgres databases (like Supabase or Neon) #11386

Closed
arredond opened this issue Nov 29, 2024 · 0 comments · Fixed by #11389
Assignees

Comments

@arredond
Copy link
Contributor

What is the bug?

Hosted Postgres solutions like Supabase or Neon frequently set the search path to an empty string. When this happens, GDAL ends up composing an invalid search path and producing an error with the message ERROR: relation "geometry_columns" does not exist (despite the geometry_columns view not being the actual issue).

This can be worked around by setting the ACTIVE_SCHEMA open option to any valid schema (like public).

Steps to reproduce the issue

Copy the following snippet in a terminal to list tables from a Supabase database using a read-only user. This should be successful the first time:

ogrinfo -so -al "postgresql://read_only_user.amcliteeqmfizqcmlmpf:read_only_pwd@aws-0-us-east-1.pooler.supabase.com:6543/postgres"

Now run the same command again and verify that you see the following error:

ERROR 1: ERROR:  zero-length delimited identifier at or near """"
LINE 1: SET search_path='',"", "$user", public, extensions
                           ^

ERROR 1: ERROR:  function postgis_version() does not exist
LINE 1: SELECT postgis_version()
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

INFO: Open of `postgresql://read_only_user.amcliteeqmfizqcmlmpf:read_only_pwd@aws-0-us-east-1.pooler.supabase.com:6543/postgres'
      using driver `PostgreSQL' successful.
ERROR 1: ERROR:  relation "geometry_columns" does not exist
LINE 1: ... JOIN pg_namespace n ON c.relnamespace=n.oid JOIN geometry_c...
                                                             ^

ERROR 1: ERROR:  relation "geometry_columns" does not exist
LINE 1: ... JOIN pg_namespace n ON c.relnamespace=n.oid JOIN geometry_c...

To understand what's going on, we can log into the database using psql and show the current search path at every step:

psql -Atx "postgresql://read_only_user.amcliteeqmfizqcmlmpf:read_only_pwd@aws-0-us-east-1.pooler.supabase.com:6543/postgres"

And now, inside the Postgres shell:

-- Before running any ogrinfo commands
SHOW search_path;  --  Returns an empty string: `""`

-- After running the ogrinfo command once (successfully) - GDAL has appended the schema where it found the PostGIS extension
SHOW search_path; -- Returns "", extensions

-- When running the ogrinfo command again, GDAL composes an invalid search path and fails

Versions and provenance

  • GDAL version: GDAL 3.10.0, released 2024/11/01
  • Operating system: macOS Sonoma 14.5 (23F79)
  • Installed via homebrew

In this example, Postgres and PostGIS versions are managed by Supabase and outside the user's control:

  • Postgres version: PostgreSQL 15.6 on aarch64-unknown-linux-gnu, compiled by gcc (GCC) 13.2.0, 64-bit
  • PostGIS version: 3.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

Additional context

No response

@arredond arredond changed the title Failure listing tables from hosted Postgres databases (like Supabase or Neon) Invalid search path when listing tables from hosted Postgres databases (like Supabase or Neon) Nov 29, 2024
rouault added a commit to rouault/gdal that referenced this issue Nov 29, 2024
… '"", something_else'

Fixes OSGeo#11386
Continuation of fix of ab40f2d / PR OSGeo#10980 that was incomplete
@rouault rouault self-assigned this Nov 29, 2024
rouault added a commit that referenced this issue Dec 2, 2024
… '"", something_else'

Fixes #11386
Continuation of fix of ab40f2d / PR #10980 that was incomplete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants