Skip to content

c/driver/postgresql: following 0.7.0 can only write into the "public" schema for PostgreSQL, irrespective of db_schema_name #1109

@alexander-beedie

Description

@alexander-beedie

PostgreSQL driver/backend doesn't honour the value of the new db_schema_name.
Currently ingest only seems to write into the "public" schema.

Ref: #1056.

Example

from adbc_driver_postgresql.dbapi import connect
import pyarrow as pa

test_data = pa.Table.from_pydict({
    "key": ["aa", "bb", "cc"], 
    "value": [10, 20, 30], 
})

# adjust URI as needed (I have a test instance in a local container)
uri = "postgresql://postgres@localhost:5432/postgres"

# schema/table into which the test data will be written
target_table = "tbl_test_data"
target_schema = "demo_schema"
create_schema = f"CREATE SCHEMA IF NOT EXISTS {target_schema}"

# ingest, setting the target db schema name
with connect(uri) as conn, conn.cursor() as cursor:
    cursor.execute(create_schema)
    
    cursor.adbc_ingest(
        table_name = target_table,
        data = test_data,
        mode = "create",
        db_schema_name = target_schema,
    )
    conn.commit()

Result

  • Table written to "public" schema; "demo_schema" (the declared target schema) is empty.

    Screenshot 2023-09-27 at 00 02 46
    with connect(uri) as conn, conn.cursor() as cursor:
        cursor.execute(f"SELECT * FROM {target_schema}.{target_table}")
        print( cursor.fetch_arrow_table() )
    
    # adbc_driver_manager.ProgrammingError: NOT_FOUND: [libpq] Failed to execute query: 
    # could not infer schema: failed to prepare query: 
    # ERROR:  relation "demo_schema.tbl_test_data" does not exist
    # LINE 1: SELECT * FROM demo_schema.tbl_test_data

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions