sql

grav 2025-03-10T07:29:51.338589Z

In Snowflake, the syntax for looking up a field in an "Object" column (which corresponds to JSON Objects) is

SELECT myObject:myField FROM ...
Is there a way to express this with HoneySQL?

valerauko 2025-03-12T12:20:15.599819Z

technically i assume you could [:raw it couldn't you?

seancorfield 2025-03-12T16:13:03.801169Z

As a workaround, yeah, :raw lets you paper over a lot of cracks. I'm happy to add support for [..`]` notation since that's potentially useful to other dialects. I'm not so keen on introducing syntax for a:b.c (rather than a.b.c or (a).b.c which are the more common SQL syntax, which HoneySQL already supports).

πŸ‘ 2
grav 2025-03-12T18:14:07.436999Z

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

πŸ‘πŸ» 1
grav 2025-03-12T18:14:16.692249Z

Thanks for looking into it @seancorfield πŸ‘

seancorfield 2025-03-12T22:10:00.329299Z

Fixed on develop. You can either use git deps or the 2.6.9999-SNAPSHOT to test it. :.:. for the a:b.c style access or :at for the a['b']['c'] style access.

seancorfield 2025-03-12T22:25:38.354349Z

(just noticed this thread was in #sql rather than #honeysql)

πŸ˜‡ 1
kulminaator 2025-03-13T05:14:19.035419Z

snowflake also has functions to extract content from json

grav 2025-03-10T07:31:22.841039Z

I tried

(sql/format {:select [:myObject:myField] :from [:foo]})
=> ["SELECT \"myObject:myField\" FROM foo"]
(sql/format {:select ["myObject:myField"] :from [:foo]})
=> ["SELECT ? FROM foo" "myObject:myField"]

seancorfield 2025-03-10T16:36:51.193269Z

Does Snowflake support any other syntax for JSON field access? Like, ya know, all the other DBs that support JSON?

grav 2025-03-10T17:21:13.313829Z

Are you calling Snowflake a snowflake?! 😁 Apparently there’s also a bracket syntax, like myObject[β€œmyField”]

seancorfield 2025-03-10T17:30:10.785019Z

Ugh! OK. Create a GH issue with a link to that doc and I'll take a look. If it supported plain dot notation like PostgreSQL etc, you'd be good to go with the :. operator. There's also :get-in which was added for XTDB but it wraps the column name in (..`)` and then uses either . for literal field names or [..`]` for parameterized field names or indices.

grav 2025-03-13T07:20:45.586939Z

Thanks a bunch @seancorfield, works well!