@@ -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 (
@@ -4067,6 +4084,8 @@ def list_rows(
40674084 page_size : Optional [int ] = None ,
40684085 retry : retries .Retry = DEFAULT_RETRY ,
40694086 timeout : TimeoutType = DEFAULT_TIMEOUT ,
4087+ * ,
4088+ timestamp_precision : Optional [enums .TimestampPrecision ] = None ,
40704089 ) -> RowIterator :
40714090 """List the rows of the table.
40724091
@@ -4115,6 +4134,11 @@ def list_rows(
41154134 before using ``retry``.
41164135 If multiple requests are made under the hood, ``timeout``
41174136 applies to each individual request.
4137+ timestamp_precision (Optional[enums.TimestampPrecision]):
4138+ [Private Preview] If set to `enums.TimestampPrecision.PICOSECOND`,
4139+ timestamp columns of picosecond precision will be returned with
4140+ full precision. Otherwise, will truncate to microsecond
4141+ precision.
41184142
41194143 Returns:
41204144 google.cloud.bigquery.table.RowIterator:
@@ -4148,7 +4172,12 @@ def list_rows(
41484172 if start_index is not None :
41494173 params ["startIndex" ] = start_index
41504174
4151- params ["formatOptions.useInt64Timestamp" ] = True
4175+ # Cannot specify both use_int64_timestamp and timestamp_output_format.
4176+ if timestamp_precision == enums .TimestampPrecision .PICOSECOND :
4177+ params ["formatOptions.timestampOutputFormat" ] = "ISO8601_STRING"
4178+ else :
4179+ params ["formatOptions.useInt64Timestamp" ] = True
4180+
41524181 row_iterator = RowIterator (
41534182 client = self ,
41544183 api_request = functools .partial (self ._call_api , retry , timeout = timeout ),
0 commit comments