def query(self, sql: str, *params: Any, retry: bool = True) -> List[Tuple[Any, ...]]:
        """Execute *sql* query with *params* and optionally return results.

        :param sql: SQL statement to execute.
        :param params: parameters to pass.
        :param retry: whether the query should be retried upon failure or given up immediately.

        :returns: a query response as a list of tuples if there is any.
        :raises:
            :exc:`~psycopg.Error` if had issues while executing *sql*.

            :exc:`~patroni.exceptions.PostgresConnectionException`: if had issues while connecting to the database.

            :exc:`~patroni.utils.RetryFailedError`: if it was detected that connection/query failed due to PostgreSQL
            restart or if retry deadline was exceeded.
        """
        if not retry:
            return self._query(sql, *params)
        try:
            return self.retry(self._query, sql, *params)
        except RetryFailedError as exc:
            raise PostgresConnectionException(str(exc)) from exc
Execute *sql* query with *params* and optionally return results.

        :param sql: SQL statement to execute.
        :param params: parameters to pass.
        :param retry: whether the query should be retried upon failure or given up immediately.

        :returns: a query response as a list of tuples if there is any.
        :raises:
            :exc:`~psycopg.Error` if had issues while executing *sql*.

            :exc:`~patroni.exceptions.PostgresConnectionException`: if had issues while connecting to the database.

            :exc:`~patroni.utils.RetryFailedError`: if it was detected that connection/query failed due to PostgreSQL
            restart or if retry deadline was exceeded.
        
patroni/postgresql/__init__.py