DB-API Reference#
Google BigQuery implementation of the Database API Specification v2.0.
This module implements the Python Database API Specification v2.0 (DB-API) for Google BigQuery.
-
google.cloud.bigquery.dbapi.
connect
(client=None)[source]# Construct a DB-API connection to Google BigQuery.
- Parameters
client (
Client
) – (Optional) A client used to connect to BigQuery. If not passed, a client is created using default options inferred from the environment.- Return type
- Returns
A new DB-API connection to BigQuery.
-
class
google.cloud.bigquery.dbapi.
Connection
(client)[source]# Bases:
object
DB-API Connection to Google BigQuery.
- Parameters
client (
Client
) – A client used to connect to BigQuery.
-
class
google.cloud.bigquery.dbapi.
Cursor
(connection)[source]# Bases:
object
DB-API Cursor to Google BigQuery.
- Parameters
connection (
Connection
) – A DB-API connection to Google BigQuery.
-
execute
(operation, parameters=None, job_id=None)[source]# Prepare and execute a database operation.
Note
When setting query parameters, values which are “text” (
unicode
in Python2,str
in Python3) will use the ‘STRING’ BigQuery type. Values which are “bytes” (str
in Python2,bytes
in Python3), will use using the ‘BYTES’ type.A ~datetime.datetime parameter without timezone information uses the ‘DATETIME’ BigQuery type (example: Global Pi Day Celebration March 14, 2017 at 1:59pm). A ~datetime.datetime parameter with timezone information uses the ‘TIMESTAMP’ BigQuery type (example: a wedding on April 29, 2011 at 11am, British Summer Time).
For more information about BigQuery data types, see: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
STRUCT
/RECORD
andREPEATED
query parameters are not yet supported. See: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/3524
-
executemany
(operation, seq_of_parameters)[source]# Prepare and execute a database operation multiple times.
- Parameters
operation (str) – A Google BigQuery query string.
parameters – Sequence of many sets of parameter values.
-
fetchall
()[source]# Fetch all remaining results from the last
execute*()
call.- Return type
List[tuple]
- Returns
A list of all the rows in the results.
- Raises
InterfaceError
if called beforeexecute()
.
-
fetchmany
(size=None)[source]# Fetch multiple results from the last
execute*()
call.Note
The size parameter is not used for the request/response size. Set the
arraysize
attribute before callingexecute()
to set the batch size.- Parameters
size (int) – (Optional) Maximum number of rows to return. Defaults to the
arraysize
property value.- Return type
List[tuple]
- Returns
A list of rows.
- Raises
InterfaceError
if called beforeexecute()
.
-
fetchone
()[source]# Fetch a single row from the results of the last
execute*()
call.- Return type
- Returns
A tuple representing a row or
None
if no more data is available.- Raises
InterfaceError
if called beforeexecute()
.
-
exception
google.cloud.bigquery.dbapi.
Warning
[source]# Bases:
Exception
Exception raised for important DB-API warnings.
-
exception
google.cloud.bigquery.dbapi.
Error
[source]# Bases:
Exception
Exception representing all non-warning DB-API errors.
-
exception
google.cloud.bigquery.dbapi.
InterfaceError
[source]# Bases:
google.cloud.bigquery.dbapi.exceptions.Error
DB-API error related to the database interface.
-
exception
google.cloud.bigquery.dbapi.
DatabaseError
[source]# Bases:
google.cloud.bigquery.dbapi.exceptions.Error
DB-API error related to the database.
-
exception
google.cloud.bigquery.dbapi.
DataError
[source]# Bases:
google.cloud.bigquery.dbapi.exceptions.DatabaseError
DB-API error due to problems with the processed data.
-
exception
google.cloud.bigquery.dbapi.
OperationalError
[source]# Bases:
google.cloud.bigquery.dbapi.exceptions.DatabaseError
DB-API error related to the database operation.
These errors are not necessarily under the control of the programmer.
-
exception
google.cloud.bigquery.dbapi.
IntegrityError
[source]# Bases:
google.cloud.bigquery.dbapi.exceptions.DatabaseError
DB-API error when integrity of the database is affected.
-
exception
google.cloud.bigquery.dbapi.
InternalError
[source]# Bases:
google.cloud.bigquery.dbapi.exceptions.DatabaseError
DB-API error when the database encounters an internal error.
-
exception
google.cloud.bigquery.dbapi.
ProgrammingError
[source]# Bases:
google.cloud.bigquery.dbapi.exceptions.DatabaseError
DB-API exception raised for programming errors.
-
exception
google.cloud.bigquery.dbapi.
NotSupportedError
[source]# Bases:
google.cloud.bigquery.dbapi.exceptions.DatabaseError
DB-API error for operations not supported by the database or API.
-
google.cloud.bigquery.dbapi.
Date
# alias of
datetime.date
-
google.cloud.bigquery.dbapi.
DateFromTicks
()# timestamp -> local date from a POSIX timestamp (like time.time()).
-
google.cloud.bigquery.dbapi.
Time
# alias of
datetime.time
-
google.cloud.bigquery.dbapi.
TimeFromTicks
(ticks, tz=None)[source]# Construct a DB-API time value from the given ticks value.
- Parameters
ticks (float) – a number of seconds since the epoch; see the documentation of the standard Python time module for details.
tz (
datetime.tzinfo
) – (Optional) time zone to use for conversion
- Return type
- Returns
time represented by ticks.
-
google.cloud.bigquery.dbapi.
Timestamp
# alias of
datetime.datetime
-
google.cloud.bigquery.dbapi.
TimestampFromTicks
()# timestamp[, tz] -> tz’s local time from POSIX timestamp.