GAQL: How can I retrieve the expected number of rows before retrieving them?

61 views
Skip to first unread message

MS

unread,
Aug 29, 2025, 10:36:28 AM (7 days ago) Aug 29
to Google Ads API and AdWords API Forum
Sometimes, a GAQL SearchStream() query may take quite a long time to run (and may exhaust memory) because of an unexpected large number of rows returned.

So, Is there a way to retrieve a query's expected number of rows beforehand?

In SQL, I would write a COUNT(…) query for that purpose.

In GAQL, I wish there would be something similar, like:

SELECT COUNT(
  campaign.name
, campaign_criterion.keyword.match_type
, campaign_criterion.keyword.text
)
FROM campaign_criterion
WHERE campaign_criterion.keyword.text IS NOT NULL

… Is there something similar to this available in GAQL?

Google Ads API Forum Advisor

unread,
Aug 29, 2025, 2:43:43 PM (6 days ago) Aug 29
to axe...@axeldahmen.de, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team.

Note that the Google Ads API does not provide a direct method to retrieve the total expected number of rows before executing a Search or SearchStream

Additionally, the 'COUNT()' function is not supported in the Google Ads API, and there isn't a similar function available in GAQL for this purpose. For more details on the Google Ads Query Language Grammar, please refer to the official documentation.

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-08-29 18:42:39Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01u5Uw5:ref" (ADR-00331366)



MS

unread,
Aug 30, 2025, 5:28:49 AM (6 days ago) Aug 30
to Google Ads API and AdWords API Forum
Hi,

thank you for your reply.

I believe this feature is crucial when downloading an unknown amout of data.

Is there a place to submit feature requests?

Your answer is appreciated.

Google Ads API Forum Advisor

unread,
Sep 1, 2025, 2:08:28 AM (4 days ago) Sep 1
to axe...@axeldahmen.de, adwor...@googlegroups.com

Hi,

Please note that you can't get a row count before a GAQL search using a COUNT() function like you would in SQL. It's not a supported feature, and it's not possible to submit a feature request for it.

However, you can use the return_total_results_count field to get a similar result. By setting this field to True in your search request, the Google Ads API will return the total number of rows that match your query, regardless of any LIMIT clause. This field is set to False by default.


Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-09-01 06:07:40Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01u5Uw5:ref" (ADR-00331366)



Axel Dahmen

unread,
Sep 1, 2025, 7:29:30 AM (4 days ago) Sep 1
to Google Ads API Forum Advisor, adwor...@googlegroups.com

Thanks for the excellent answer!

This is the solution I was looking for. A thing like that is necessary to avoid buffer overruns, memory exhaustion etc.

However, in my personal repository I will extend my GAQL parser for transpiling a corresponding COUNT clause into the SearchSettings option you described.

Best regards

Axel Dahmen

unread,
Sep 1, 2025, 11:43:37 AM (4 days ago) Sep 1
to Google Ads API Forum Advisor, adwor...@googlegroups.com

Hi,

I couldn't find an example on how to apply the SearchSettings object in a GAQL query in the documentation.

How can I apply this setting to SearchStreamAsync?

Your answer is appreciated.

Regards

Google Ads API Forum Advisor

unread,
Sep 1, 2025, 2:45:22 PM (3 days ago) Sep 1
to axe...@axeldahmen.de, adwor...@googlegroups.com
Hi,

The SearchSettings is not available in a GAQL query. This setting is instead available within the 'Search' method. For example:
POST https://googleads.googleapis.com/v21/customers/xxxxxxxxxx/googleAds:search?key=[YOUR_API_KEY] HTTP/1.1

developer-token: **********************
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json

{
  "query": "SELECT ad_group.id, geographic_view.country_criterion_id, geographic_view.location_type, campaign.id, ad_group.id, segments.device, segments.ad_network_type, metrics.clicks, metrics.cost_micros, metrics.impressions, campaign.advertising_channel_type FROM geographic_view",
  "searchSettings": {
    "returnTotalResultsCount": true
  }
}
 

It's also important to note that it's not possible to apply SearchSettings in the SearchStream method, as this method will have SummaryRowSetting with different enum values compared to the Search method.

I hope this clarifies. Feel free to get back to us if you have any further questions.  

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-09-01 18:44:24Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01u5Uw5:ref" (ADR-00331366)



Axel Dahmen

unread,
Sep 2, 2025, 12:55:39 PM (3 days ago) Sep 2
to Google Ads API Forum Advisor, adwor...@googlegroups.com

Hi,

thank for you for clarifying.

I tried using the suggested SearchSettings object, but I'm not getting any result from the SearchAsync() method.

I'm using the Google Ads .NET client library. Should I file a bug report there?

Your answer is appreciated.

Google Ads API Forum Advisor

unread,
Sep 2, 2025, 3:47:50 PM (2 days ago) Sep 2
to axe...@axeldahmen.de, adwor...@googlegroups.com
Hi,

To analyse the issue further, please share the below details : As you are using a .NET client library, you can refer to the .Net guide to enable logging at your end. 

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-09-02 19:46:38Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01u5Uw5:ref" (ADR-00331366)



Axel Dahmen

unread,
Sep 2, 2025, 7:25:52 PM (2 days ago) Sep 2
to Google Ads API Forum Advisor, adwor...@googlegroups.com

Hi,

thanks again for your answer.

In the meantime, I created a bug report on GitHub for the Google Ads .NET team

https://github.com/googleads/google-ads-dotnet/issues/617

I guess this is an inherent issue with the Google Ads client implementation generator: There's simply no corresponding return value implemented in the client libraries. So, the issue may eventually be forwarded to the protocolbuffers/protobuf team.

Perhaps there's a special method for retrieving the Total Expected Rows Count value somewhere. But we'll have to await the progress of that bug report.

Best regards

Reply all
Reply to author
Forward
0 new messages