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?technically i assume you could [:raw it couldn't you?
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).
Thanks for looking into it @seancorfield π
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.
(just noticed this thread was in #sql rather than #honeysql)
snowflake also has functions to extract content from json
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"]Does Snowflake support any other syntax for JSON field access? Like, ya know, all the other DBs that support JSON?
Are you calling Snowflake a snowflake?! π
Apparently thereβs also a bracket syntax, like myObject[βmyFieldβ]
https://docs.snowflake.com/en/user-guide/querying-semistructured#traversing-semi-structured-data
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.
Thanks a bunch @seancorfield, works well!