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

c/driver/postgresql: GetTableSchema does not properly handle catalog or db_schema parameters #1339

Closed
joellubi opened this issue Dec 4, 2023 · 2 comments · Fixed by #1387
Assignees

Comments

@joellubi
Copy link
Member

joellubi commented Dec 4, 2023

When calling GetTableSchema on the postgresql driver, the following behavior is observed:

  1. catalog is ignored
  2. The query produced when db_schema is set causes a postgres syntax error

I have been able to reproduce the issues with Go and Python bindings. Below are the steps for reproducing in Python:

from adbc_driver_postgresql import dbapi

uri = "postgresql://postgres@localhost:5432/postgres"

# Setup example
with dbapi.connect(uri) as conn:
    with conn.cursor() as cur:
        cur.execute("CREATE TABLE foo (bar int)")
    conn.commit()

# Correct, inferring catalog: postgres, db_schema: public
with dbapi.connect(uri) as conn:
    schema = conn.adbc_get_table_schema("foo")
print(schema) # bar: int32

#  Incorrect, catalog_filter is ignored
with dbapi.connect(uri) as conn:
    schema = conn.adbc_get_table_schema("foo", catalog_filter="doesnt_exist")
print(schema) # bar: int32

#  Incorrect, raises exception when foo should be found in public schema
with dbapi.connect(uri) as conn:
    schema = conn.adbc_get_table_schema("foo", db_schema_filter="public")

# Exception raised
OperationalError: ADBC_STATUS_IO (10): [libpq] Failed to prepare query: ERROR:  syntax error at or near "$2"
LINE 1: ...= typ.oid WHERE attr.attnum >= 0 AND cls.oid = $1.$2::regcla...
                                                             ^

Query was:SELECT attname, atttypid FROM pg_cat

Version Info
Python: 3.11.4
adbc_driver_postgresql: 0.8.0

@joellubi
Copy link
Member Author

joellubi commented Dec 4, 2023

@lidavidm lidavidm added this to the ADBC Libraries 0.9.0 milestone Dec 5, 2023
@lidavidm lidavidm modified the milestone: ADBC Libraries 0.9.0 Dec 19, 2023
@lidavidm lidavidm self-assigned this Dec 20, 2023
@lidavidm
Copy link
Member

lidavidm commented Dec 20, 2023

In Postgres, you can only access the database (catalog) you're connected to.

A client connection to the server can only access data in a single database, the one specified in the connection request.

(https://www.postgresql.org/docs/current/ddl-schemas.html)

However we should support schemas properly.

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

Successfully merging a pull request may close this issue.

2 participants