honeysql

István Karaszi 2025-05-13T08:46:04.302739Z

Removing unnecessary parens (unnesting) I am doing an experiment to use HoneySQL for formatting Google Ads queries, but unfortunately Google does not like parens around the where conditions. Is there a way to remove them?

István Karaszi 2025-05-13T08:48:16.158379Z

Technically to generate the following SQL:

SELECT geo_target_constant.id, geo_target_constant.name, geo_target_constant.target_type, geo_target_constant.country_code, geo_target_constant.canonical_name, geo_target_constant.status FROM geo_target_constant WHERE geo_target_constant.name LIKE 'Hungary%' AND geo_target_constant.country_code = 'HU'
Instead of:
SELECT geo_target_constant.id, geo_target_constant.name, geo_target_constant.target_type, geo_target_constant.country_code, geo_target_constant.canonical_name, geo_target_constant.status FROM geo_target_constant WHERE (geo_target_constant.name LIKE 'Hungary%') AND (geo_target_constant.country_code = 'HU')

István Karaszi 2025-05-13T08:51:03.611799Z

I tried to play with the dialects, but that did not help

seancorfield 2025-05-13T12:51:05.380349Z

So Google Ads does not support compound queries where you would need parens to override precedence? Can you provide a link to the docs for this?

István Karaszi 2025-05-13T12:51:44.170329Z

They don’t support complex queries they don’t even support OR conditions according to the docs: https://developers.google.com/google-ads/api/docs/query/structure#where

István Karaszi 2025-05-13T12:52:50.784879Z

I did a string hackity-hack, which works now, but I wanted ask, since technically parens aren’t required AFAIK for “flat” where conditions

seancorfield 2025-05-13T12:54:56.460839Z

Create a GH issue and I'll give it some thought. It's all baked into the operator formatting right now and there's no way to override the parens. You can add nesting but not take it away.

István Karaszi 2025-05-13T12:55:22.071369Z

Yes, I saw the functionality for the nesting and adding extra wrapping, but not the opposite

István Karaszi 2025-05-13T12:55:25.832579Z

Creating a ticket now, thank you!

István Karaszi 2025-05-13T12:56:13.306999Z

But before, I started to sponsor you 🙂

István Karaszi 2025-05-13T12:56:35.102019Z

It is a long time overdue

István Karaszi 2025-05-13T13:00:36.497159Z

https://github.com/seancorfield/honeysql/issues/574

seancorfield 2025-05-13T13:28:20.366569Z

Thank you! On both counts.

István Karaszi 2025-05-13T13:28:49.393759Z

Thank you for the great libraries and all your efforts

❤️ 1
seancorfield 2025-05-13T13:41:26.649419Z

The production of ( .. ) around sub-expressions is baked into a lot of the formatting via a :nested option that is passed down the tree so inventing a way to ignore that in some situations will be a bit tricky... but I may be able to do something fairly localized to allow the limited Google Ads case(s) maybe...

István Karaszi 2025-05-13T13:42:23.219499Z

That would be great! Don’t stress too much about it, but maybe keep that in back of your mind when you doing some refactoring around the functionality.

István Karaszi 2025-05-13T13:43:38.916789Z

What I do know is super ugly but works, I am using (format data {:inline true}) and then doing string manipulations to remove the wrappings.

2025-05-13T13:00:30.886509Z

2025-05-14T02:23:19.561749Z