@@ -3469,6 +3469,8 @@ def query(
34693469 timeout : TimeoutType = DEFAULT_TIMEOUT ,
34703470 job_retry : Optional [retries .Retry ] = DEFAULT_JOB_RETRY ,
34713471 api_method : Union [str , enums .QueryApiMethod ] = enums .QueryApiMethod .INSERT ,
3472+ * ,
3473+ timestamp_precision : Optional [enums .TimestampPrecision ] = None ,
34723474 ) -> job .QueryJob :
34733475 """Run a SQL query.
34743476
@@ -3524,6 +3526,11 @@ def query(
35243526
35253527 See :class:`google.cloud.bigquery.enums.QueryApiMethod` for
35263528 details on the difference between the query start methods.
3529+ timestamp_precision (Optional[enums.TimestampPrecision]):
3530+ [Private Preview] If set to `enums.TimestampPrecision.PICOSECOND`,
3531+ timestamp columns of picosecond precision will be returned with
3532+ full precision. Otherwise, will truncate to microsecond
3533+ precision. Only applies when api_method == `enums.QueryApiMethod.QUERY`.
35273534
35283535 Returns:
35293536 google.cloud.bigquery.job.QueryJob: A new query job instance.
@@ -3543,6 +3550,15 @@ def query(
35433550 "`job_id` was provided, but the 'QUERY' `api_method` was requested."
35443551 )
35453552
3553+ if (
3554+ timestamp_precision == enums .TimestampPrecision .PICOSECOND
3555+ and api_method != enums .QueryApiMethod .QUERY
3556+ ):
3557+ raise ValueError (
3558+ "Picosecond Timestamp is only supported when `api_method "
3559+ "== enums.QueryApiMethod.QUERY`."
3560+ )
3561+
35463562 if project is None :
35473563 project = self .project
35483564
@@ -3568,6 +3584,7 @@ def query(
35683584 retry ,
35693585 timeout ,
35703586 job_retry ,
3587+ timestamp_precision = timestamp_precision ,
35713588 )
35723589 elif api_method == enums .QueryApiMethod .INSERT :
35733590 return _job_helpers .query_jobs_insert (
@@ -4062,6 +4079,8 @@ def list_rows(
40624079 page_size : Optional [int ] = None ,
40634080 retry : retries .Retry = DEFAULT_RETRY ,
40644081 timeout : TimeoutType = DEFAULT_TIMEOUT ,
4082+ * ,
4083+ timestamp_precision : Optional [enums .TimestampPrecision ] = None ,
40654084 ) -> RowIterator :
40664085 """List the rows of the table.
40674086
@@ -4110,6 +4129,11 @@ def list_rows(
41104129 before using ``retry``.
41114130 If multiple requests are made under the hood, ``timeout``
41124131 applies to each individual request.
4132+ timestamp_precision (Optional[enums.TimestampPrecision]):
4133+ [Private Preview] If set to `enums.TimestampPrecision.PICOSECOND`,
4134+ timestamp columns of picosecond precision will be returned with
4135+ full precision. Otherwise, will truncate to microsecond
4136+ precision.
41134137
41144138 Returns:
41154139 google.cloud.bigquery.table.RowIterator:
@@ -4143,7 +4167,12 @@ def list_rows(
41434167 if start_index is not None :
41444168 params ["startIndex" ] = start_index
41454169
4146- params ["formatOptions.useInt64Timestamp" ] = True
4170+ # Cannot specify both use_int64_timestamp and timestamp_output_format.
4171+ if timestamp_precision == enums .TimestampPrecision .PICOSECOND :
4172+ params ["formatOptions.timestampOutputFormat" ] = "ISO8601_STRING"
4173+ else :
4174+ params ["formatOptions.useInt64Timestamp" ] = True
4175+
41474176 row_iterator = RowIterator (
41484177 client = self ,
41494178 api_request = functools .partial (self ._call_api , retry , timeout = timeout ),
0 commit comments