Skip to content

Cursort.rowcount is 0 for insert statements #498

Description

@oman36

Clickhouse returns us number of inserted rows in its own way, but clickhouse-driver doesn't propagate it to users. Some API relay on rowcount for example Airflow bryzgaloff/airflow-clickhouse-plugin#116

The solution could be as follows:

from clickhouse_driver.progress import Progress

class Cursor(object):
    @property
    def rowcount(self) -> int:
        if self._types:
            # a select query or a DDL query on a cluster that returns:
            # 'host', 'port', 'status', 'error', 'num_hosts_remaining', 'num_hosts_active'
            return self._rowcount
        progress: Progress = self._client.last_query.progress
        # progress.rows shows number multiplied by number of replicase, progress.written_rows shows correct value
        return progress.written_rows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions