docstr: Cancel query in the underlying database.
  
  :param cursor: New cursor instance to the db of the query
  :param query: Query instance
  :param cancel_query_id: Postgres PID
  :return: True if query cancelled successfully, False otherwise
docstr_tok: ["Cancel","query","in","the","underlying","database",".",":","param","cursor",":","New","cursor","instance","to","the","db","of","the","query",":","param","query",":","Query","instance",":","param","cancel_query_id",":","Postgres","PID",":","return",":","True","if","query","cancelled","successfully",",","False","otherwise"]
code: def cancel_query(
      cls, cursor: Any, query: Query, cancel_query_id: str
  ) -> bool:
      """
      Cancel query in the underlying database.
  
      :param cursor: New cursor instance to the db of the query
      :param query: Query instance
      :param cancel_query_id: Postgres PID
      :return: True if query cancelled successfully, False otherwise
      """
      try:
          cursor.execute(
              "SELECT pg_terminate_backend(pid) "
              "FROM pg_stat_activity "
              f"WHERE pid='{cancel_query_id}'"
          )
      except Exception:  # pylint: disable=broad-except
          return False
  
      return True
  
imports: from __future__ import annotations
  import json
  import logging
  import re
  from datetime import datetime
  from re import Pattern
  from typing import Any, TYPE_CHECKING
  import sqlparse
  from flask_babel import gettext
  from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION, ENUM, JSON
  from sqlalchemy.dialects.postgresql.base import PGInspector
  from sqlalchemy.engine.reflection import Inspector
  from sqlalchemy.engine.url import URL
  from sqlalchemy.types import Date, DateTime, String
  from superset.constants import TimeGrain
  from superset.db_engine_specs.base import BaseEngineSpec, BasicParametersMixin
  from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
  from superset.exceptions import SupersetException, SupersetSecurityException
  from superset.models.sql_lab import Query
  from superset.utils import core
  from superset.utils.core import GenericDataType
label_desc: Use image node_id 12 for calling the PostgresEngineSpec obj's underlying member method code with example usage: obj.cancel_query(cls, cursor, query, cancel_query_id) and returns: True, False