Convert a scalar value into a query parameter.

    :type value: any
    :param value: A scalar value to convert into a query parameter.

    :type name: str
    :param name: (Optional) Name of the query parameter.

    :rtype: :class:`~google.cloud.bigquery.ScalarQueryParameter`
    :returns:
        A query parameter corresponding with the type and value of the plain
        Python object.
    :raises: :class:`~google.cloud.bigquery.dbapi.exceptions.ProgrammingError`
        if the type cannot be determined.

def scalar_to_query_parameter(value, name=None):
    """Convert a scalar value into a query parameter.

    :type value: any
    :param value: A scalar value to convert into a query parameter.

    :type name: str
    :param name: (Optional) Name of the query parameter.

    :rtype: :class:`~google.cloud.bigquery.ScalarQueryParameter`
    :returns:
        A query parameter corresponding with the type and value of the plain
        Python object.
    :raises: :class:`~google.cloud.bigquery.dbapi.exceptions.ProgrammingError`
        if the type cannot be determined.
    """
    parameter_type = None

    if isinstance(value, bool):
        parameter_type = "BOOL"
    elif isinstance(value, numbers.Integral):
        parameter_type = "INT64"
    elif isinstance(value, numbers.Real):
        parameter_type = "FLOAT64"
    elif isinstance(value, decimal.Decimal):
        parameter_type = "NUMERIC"
    elif isinstance(value, six.text_type):
        parameter_type = "STRING"
    elif isinstance(value, six.binary_type):
        parameter_type = "BYTES"
    elif isinstance(value, datetime.datetime):
        parameter_type = "DATETIME" if value.tzinfo is None else "TIMESTAMP"
    elif isinstance(value, datetime.date):
        parameter_type = "DATE"
    elif isinstance(value, datetime.time):
        parameter_type = "TIME"
    else:
        raise exceptions.ProgrammingError(
            "encountered parameter {} with value {} of unexpected type".format(
                name, value
            )
        )
    return bigquery.ScalarQueryParameter(name, parameter_type, value)