Skip to content

HANA table fails with Could not find table/view CONSTRAINT_COLUMNS when trying to read column names #153

@Pineappletooth

Description

@Pineappletooth

Complete error:

Error loading columns: (259, 'invalid table name: Could not find table/view CONSTRAINT_COLUMNS in schema SYS: line 1 col 55 (at pos 54)')

Seems to be caused by wrong queries in get_columns from Hana adapter, i don't know if its due to different versions of HANA, this query fixes it on my end.

    def get_columns(
        self, conn: Any, table: str, database: str | None = None, schema: str | None = None
    ) -> list[ColumnInfo]:
        cursor = conn.cursor()
        schema = schema or self.default_schema

        cursor.execute(
            "SELECT column_name "
            "FROM sys.constraints "
            "WHERE is_primary_key = true "
            "AND schema_name = ? AND table_name = ? ",
            (schema, table),
        )
        pk_columns = {row[0] for row in cursor.fetchall()}

        cursor.execute(
            "SELECT column_name, data_type_name FROM sys.table_columns "
            "WHERE schema_name = ? AND table_name = ? "
            "ORDER BY position",
            (schema, table),
        )
        return [
            ColumnInfo(name=row[0], data_type=row[1], is_primary_key=row[0] in pk_columns)
            for row in cursor.fetchall()
        ]

Connecting to HANA cloud, version 4.00.000.00.1770107678, cloud version 2025.40.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions