sql 2025-03-10

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).

πŸ‘ 2

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)

πŸ˜‡ 1

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”]

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!